[英]Python program, can anyone tell me what significance of the 2 is here?
在round函數中,數字2是第二個參數是什么意思?
##This is a program that calcs your credit card, and compounds down the total
a=float(raw_input("Enter the outstanding balance on your credit card:"))
b=float(raw_input("Enter the annual crdit card interest rate as a deicimal:"))
c=float(raw_input("Enter the minimum monthly payment as a decimal:"))
for month in range(1, 13):
print "Month: ", str(month)
MMP = round((c * a),2) ##the 2 here and below, what does it do?
print "Minimum monthly payment: ", MMP
IP = round((b/12 * a),2)
print "Interest payed: ", IP
PP = round(((c*a) - ((b/12)*a)),2)
print "principal payed: ", PP
a = round((a - PP),2)
print "Remaining balance", a
2作為舍入的第二個參數傳遞,給出舍入到的小數位數。 這會將其舍入到最接近的浮點數,該數字代表四舍五入到小數點后兩位的數字。 請注意,這是一個非常糟糕的主意,並且是錯誤的常見來源。 請使用分數,分數或十進制。十進制代替。
浮點數絕不能用來賺錢,尤其是當您像這樣對它們進行四舍五入時。
2
是舍入運算中使用的小數位數。 在這里看看: http : //docs.python.org/library/functions.html#round
這將舍入一個數字,以便在操作后它具有2個十進制數字。 檢查以下文檔:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.