this imagine extremely simple - why in following 2 values y not == 0? thought whole point of decimal module rid of float dust ...the following extremely simplified version of mathematical routine passes numbers around variables.
from decimal import * getcontext().prec = 2 q = decimal(0.01) x = decimal(0.10) * decimal(0.10) y = decimal(x) - decimal(q) print(x,y, decimal(y)) ''' x== 0.010 y== -2.1e-19 decimal(y) == -2.1e-19 '''
try specifying numbers strings
>>> decimal('0.10') * decimal('0.10') - decimal('0.0100') >>> decimal('0.000')
Comments
Post a Comment