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