python进行四舍五入

from decimal import Decimal

# .2f设置小数位精确位数, 如下返回2.55

q = 2.551

t = format(Decimal(q),  '.2f')

#向上取2位小数, 返回2.56

q = 2.551

t = format(Decimal( q + 0.005),  '.2f')

原文地址:https://www.cnblogs.com/zpf1092841490/p/10049076.html