9 Mar
2014
9 Mar
'14
1:36 p.m.
Steven D'Aprano
Note that this round-trips back to float correctly:
py> assert float(d) == 9017.010981286436
Many inexact values map to the same float.
So I must admit, I'm not sure where the extra digits come from:
Decimal('9017.01098128643570817075669765472412109375') Decimal('9017.010981286435708170756694')
Without looking at your calculation, I guess it is rounding:
9017.010981286436.as_integer_ratio() (2478577105427079, 274877906944) Decimal(2478577105427079) / 274877906944 Decimal('9017.010981286435708170756698') getcontext().prec = 100 Decimal(2478577105427079) / 274877906944 Decimal('9017.01098128643570817075669765472412109375')
Stefan Krah