There are two misunderstandings here.
One, not all floating points can be represented perfectly accurately by computers.
Read more here to understand this issue:
https://en.wikipedia.org/wiki/Floating-point_arithmetic
The second is that this is mostly a display issue:
Converting dollars to cents you have a couple options, use the
One, not all floating points can be represented perfectly accurately by computers.
Read more here to understand this issue:
https://en.wikipedia.org/wiki/Floating-point_arithmetic
The second is that this is mostly a display issue:
>>> 1.15*100 114.99999999999999 >>> print(1.15*100) 115.0 >>>In terms of money it is often best to do all calculations in cents until the end.
Converting dollars to cents you have a couple options, use the
decimal
module>>> from decimal import Decimal >>> a = Decimal("1.15") >>> a * 100 Decimal('115.00') >>>Or in this case you can probably just use
round
.>>> int(round(1.15*100)) 115 >>>