小编pyt*_*ewb的帖子

在Python中回答2位小数的答案

我遇到的问题是我将结果四舍五入到小数点后两位.我的应用程序获得了正确的结果,但是,我很难将应用程序舍入到最接近的小数,就像使用货币一样

cost = input("\nEnter the 12 month cost of the Order: ")
cost = float(cost)

print("\n12 Month Cost:",
  cost * 1,"USD")
print("6 Month Cost:",
  cost * 0.60,"USD")
print("3 Month Cost:",
  cost * 0.36,"USD")
Run Code Online (Sandbox Code Playgroud)

所以例如,如果12个月的价格是23美元,6个月的价格是13.799999999999999但我希望它显示13.80

我已经环顾了谷歌以及如何围绕一个数字,但在舍入结果方面找不到多少帮助.

python currency rounding

9
推荐指数
1
解决办法
1万
查看次数

标签 统计

currency ×1

python ×1

rounding ×1