关于python保留几位小数,不进行四舍五入的方法

法一

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
原文地址:https://www.cnblogs.com/twfb/p/6202874.html