def cut(num,c):
c=10**(-c)
return (num//c)*c
print (cut(2.999,2))
由于对浮点数进行操作所以会产生精度误差, 还需大家考虑
例如:
print(cut(0.99999999999999999999999999,12))
#1.0
def cut(num,c):
c=10**(-c)
return (num//c)*c
print (cut(2.999,2))
由于对浮点数进行操作所以会产生精度误差, 还需大家考虑
例如:
print(cut(0.99999999999999999999999999,12))
#1.0
转载于:https://www.cnblogs.com/edhg/p/6202874.html