round down to 2 decimal in python

后端 未结 5 1406
我寻月下人不归
我寻月下人不归 2020-12-01 18:46

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

a = 28.266
print round(a, 2)

28.27

<
5条回答
  •  粉色の甜心
    2020-12-01 19:22

    simply try this:

    import math
    a = 28.266
    print((math.floor(a * 100)) / 100.0)
    

    Output:

    28.26
    

提交回复
热议问题