0

Python 3:

  1. 234324234324234/10 gives 23432423432423.4
  2. whereas 23432423432423434/10 gives 2343242343242343.5
  3. and 46374212988031352/10 gives 4637421298803135.0

Why do I get unexpected outputs in the decimal places?

1 Answers1

0

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')
Guillaume Thomas
  • 2,220
  • 2
  • 24
  • 33