答案 0 :(得分:3)
如果您要在每次循环计算付款时,您还要减少期限并保持欠款金额。像这样:
periods.times do |period|
# the monthly payment
monthly_payment = loan_amount * ( (rate * ( 1 + rate)**periods) / ( ( 1 + rate )**periods - 1) )
periods -= 1
loan_amount = loan_amount * (1 + rate) - monthly_payment
end
您应该注意到每月付款保持不变。你可以在循环之前真正计算它然后看起来像这样:
# the monthly payment
monthly_payment = loan_amount * ( (rate * ( 1 + rate)**periods) / ( ( 1 + rate )**periods - 1) )
periods.times do |period|
loan_amount = loan_amount * (1 + rate) - monthly_payment
end
然后loan_amount将是每个月末的欠款。
如果付款看起来很高,那是因为您的利率可能是年利率,可以除以12。
答案 1 :(得分:0)
periods.times do |period|
# the monthly payment
loan_amount = loan_amount - 1
# loan_amount -= 1 #this is better
monthly_payment = loan_amount *( (rate * ( 1 + rate)**periods) / ( ( 1 + rate )**periods - 1) )
end