简体   繁体   English

用Java计算折扣系数

[英]Calculating discount factor in java

I am trying to calculate monthly loan payments the formula Loan Payment = Amount / Discount Factor on www.thebalance.com According to the website discount factor is calculated with this formula (D) = {[(1 + i) ^n] - 1} / [i(1 + i)^n] I tried interpreting this into Java and came up with 我正在尝试计算www.thebalance.com上的贷款偿还额=金额/折扣因数的公式,根据网站的折扣因数是使用此公式计算的(D) = {[(1 + i) ^n] - 1} / [i(1 + i)^n]我尝试将其解释为Java,并提出了

double discountFactor = (Math.pow((1 + interest), numberOfPayments) - 1) / Math.pow(interest * (1 + interest), numberOfPayments);

But it outputs infinity am not so good with Math, can someone help point out the issue? 但是它对Math的输出infinity ,有人可以指出这个问题吗?

double discountFactor = (Math.pow((1 + interest), numberOfPayments) - 1) /
                        (interest  * Math.pow((1 + interest), numberOfPayments));

interest is not part of the power, it should be outside power. interest不是权力的一部分,它应该是权力的外部。

将“利息”放在第二个幂函数之外,而不是在里面。

double discountFactor = (Math.pow((1 + interest),numberOfPayments)-1)/(interest*Math.pow((1+interest),numberOfPayments));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM