Search code examples
pythonrounding-error

When I round x in python it returns 0.0


When I try to run print(round(x, 2)) it shows as 0.0.


Solution

  • It will round to 0 if x is smaller then 0.005.

    x = 0.005
    round(x, 2)
    > 0.01
    
    x = 0.0049
    round(x, 2)
    > 0.00