Need help with precision in python

Hi all,

Im trying to calculate something and i want it to be precise.
this is what i got, but it seems to not give me an outcome:
image

This is the pythoncode i m using:

import clr
clr.AddReference(‘ProtoGeometry’)
from Autodesk.DesignScript.Geometry import *
clr.AddReference(‘RevitServices’)
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
import sys
sys.path.append(‘C:\Program Files (x86)\IronPython 2.7\Lib’)
from decimal import *
#getcontext().rounding = ROUND_HALF_UP
from math import *
#getcontext().prec = 7
getcontext().prec = 28

kop = IN[0]
voeg = IN[1]
koppenmaatDynamo = IN[2]
koppenmaatPython = Decimal(kop) + Decimal(voeg)
ftmm = 304.8

kop2 = Decimal(‘10.123456789123456789’)

OUT = koppenmaatDynamo, koppenmaatPython, kop2

if i calculate 10.1234567891234 + 100 it rounds the last digit.
i m trying to sum them in python without the rounding.

any help is greatly appriciated, also if it isnt possible please let me know.

Try and have a look at this topic Python wrong outcome because it rounds my float value

Thats my own topic :stuck_out_tongue:
Then i didnt know about the python decimal module.
It should be more precise than float?

1 Like