Java Math.Pow method

2019-07-20 17:01发布

monPay = (amtFin * amtI)/((1-(1+amtI)*Math.pow(-n,-n)));

I am using this code but it is not calculating Math.pow(-n,-n) correctly. It seems like it is Math.pow(-n,-n) is calculating to 0.0. All variables have type double.

标签: java pow
2条回答
老娘就宠你
2楼-- · 2019-07-20 17:40

What happens is that the value of pow(-n,-n) is too low to be represented as a double (the minimum non-zero double in absolute value is about 10E-323).

You may work with BigDecimal instead, but note that computations with BigDecimal are slower.

查看更多
叛逆
3楼-- · 2019-07-20 17:44

It looks like you're trying to compute monthly loan repayments based on the principal amount etc. However, your formula is wrong: the (1+amtI)*Math.pow(-n,-n) should be Math.pow(1+amtI,-n).

查看更多
登录 后发表回答