Search code examples
pythonrounding

round down to 2 decimal in python


I need to round down and it should be two decimal places.
Tried the following,

a = 28.266
print round(a, 2)

28.27

But the expected value is 28.26 only.


Solution

  • Seems like you need the floor:

    import math
    math.floor(a * 100)/100.0
    
    # 28.26