法一
def cut(num, c):
str_num = str(num)
return float(str_num[:str_num.index('.') + 1 + c])
print (cut(2.999,2))
# 2.99
print (cut(1.00000001,8))
# 1.00000001
法二
def cut(num, c):
c=10**(-c)
return (num//c)*c
print (cut(2.999,2))
# 2.99
print (cut(1.00000001,8))
# 1.0