import decimal
from decimal import Decimal
context=decimal.getcontext() # 获取decimal现在的上下文
context.rounding = decimal.ROUND_05UP
print(format(Decimal(2.434), '.2f')) #'2.6'
结果:
2.43
Process finished with exit code 0
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/100686.html原文链接:https://javaforall.cn