我怎么舍入到小数点第二个小数点?

2024-04-20 04:00:03 发布

您现在位置:Python中文网/ 问答频道 /正文

我很难舍入数字。我试着把它包括在我最初的描述中,即monthlyInterestrate = round(annualInterestrate/12.0, 2)

打印时也有几种格式,例如:

print ('Minimum monthly payment: ' + str(round monthlyPayment),2)

我的表述有误吗?你知道吗

任何洞察都将不胜感激!你知道吗


Tags: 格式数字paymentprintminimum洞察strround
2条回答

这不管用吗?你知道吗

monthlyPayment = 10.126234
print ('Minimum monthly payment: ' + str(round(monthlyPayment, 2)))
print "%0.2f"%monthlyPayment 
#or
print "{0:0.2f}".format(3.45678)

如果你只是想在打印的时候把它四舍五入的话应该可以,尽管我应该提到它并不总是四舍五入的,例如3.3447 -> 3.34但是3.345 -> 3.35

相关问题 更多 >