Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 14069

Why does Python's Decimal class generate additional digits that weren't there before? [duplicate]

$
0
0

Take a look at the following outputs

>>> from decimal import Decimal>>> print(2.4)2.4>>> print(Decimal(2.4))2.399999999999999911182158029987476766109466552734375

Why exactly is this happening? If the explanation is that 2.4 couldn't be represented precisely, and therefore already had to be represented in approximate form, then how come the first print statement produced an exact result?


Viewing all articles
Browse latest Browse all 14069

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>