I want a
to be rounded to 13.95. I tried using round
, but I get:
>>> a
13.949999999999999
>>> round(a, 2)
13.949999999999999
For the analogous issue with the standard library Decimal class, see How can I format a decimal to always show 2 decimal places?.
The built-in
round()
works just fine in Python 2.7 or later.Example:
Check out the documentation.