Limiting floats to two decimal points

前端 未结 28 3194
你的背包
你的背包 2020-11-21 04:57

I want a to be rounded to 13.95.

>>> a
13.949999999999999
>>> round(a, 2)
13.949999999999999

The ro

28条回答
  •  栀梦
    栀梦 (楼主)
    2020-11-21 05:11

    What about a lambda function like this:

    arred = lambda x,n : x*(10**n)//1/(10**n)
    

    This way you could just do:

    arred(3.141591657,2)
    

    and get

    3.14
    

提交回复
热议问题