Python 3:
- 234324234324234/10 gives 23432423432423.4
- whereas 23432423432423434/10 gives 2343242343242343.5
- and 46374212988031352/10 gives 4637421298803135.0
Why do I get unexpected outputs in the decimal places?
Python 3:
Why do I get unexpected outputs in the decimal places?
You should use the decimal
module for "fast correctly-rounded decimal floating point arithmetic"
In [4]: import decimal
In [5]: decimal.Decimal(234324234324234)/10
Out[5]: Decimal('23432423432423.4')
In [6]: decimal.Decimal( 23432423432423434)/10
Out[6]: Decimal('2343242343242343.4')
In [7]: decimal.Decimal( 46374212988031352)/10
Out[7]: Decimal('4637421298803135.2')