import decimal
from decimal import Decimal
context=decimal.getcontext() # obtain decimal Current context
context.rounding = decimal.ROUND_05UP
print(format(Decimal(2.434), '.2f')) #'2.6'
result :
2.43
Process finished with exit code 0
Publisher : Full stack programmer stack length , Reprint please indicate the source :https://javaforall.cn/100686.html Link to the original text :https://javaforall.cn