interest = int(float(raw_input("Interest Rate: ")))
monintrate = int(float(( interest / 100.0 ) / 12))
annintrate = int(float(interest / 12))
print "Interest: ",interest
print "Mon Int Rate: ",monintrate
print "Ann Int Rate: ",annintrate
您好,我想将上述变量正确计算为小数,但无论出于何种原因我都无法正常工作。有人能指出我正确的方向吗?
以下是我的结果:
Interest: 5
Mon Int Rate: 0
Ann Int Rate: 0
谢谢
答案 0 :(得分:1)
删除变量之前的int,以便获得小数
interest = float(raw_input("Interest Rate: "))
monintrate = float(( interest / 100.0 ) / 12)
annintrate = float(interest / 12)
答案 1 :(得分:0)
你需要摆脱int
interest = float(raw_input("Interest Rate: "))
monintrate = round((interest / 100.0)/12, 4) """ will give 4 decimal places"""
annintrate = round((interest / 12), 4) """ will give 4 decimal places"""
print "Interest: ",interest
print "Mon Int Rate: ",monintrate
print "Ann Int Rate: ",annintrate
给出以下内容:
Interest: 5.0
Mon Int Rate: 0.0042
Ann Int Rate: 0.41667
答案 2 :(得分:0)
这样做
print month,"___","{:.2f}".format(monprnpaid),"___","{:.2f}".format(monintdue),"___","{:.2f}".format(loanbal)
谢谢大家