Search code examples
pythonpython-3.xfloating-pointprecisionfloating-accuracy

Round float in Python


I have a problem with float in Python...

I have this in a variable:

i = 9.600000000000001

And I would transform in this:

i = 9.60000

with five numbers after the decimal point and rounded.


Solution

  • >>> format(9.60000001,'.5f')                                                                                                            
    '9.60000'
    >>>