开发者

Is there an NPER or financial function library available that supports NPER functions?

开发者 https://www.devze.com 2023-04-10 01:55 出处:网络
I\'ve been scouring the internet for the better part of two days looking for a JAVA financial library that has functions similar to Excel\'s, particularly NPER.the closest thing I\'ve come to is the o

I've been scouring the internet for the better part of two days looking for a JAVA financial library that has functions similar to Excel's, particularly NPER. the closest thing I've come to is the one here:NPER formula, except when I type that into a solver here:math calculator using the following:

((√((80*(1+.13*1)+(-1/.13)*0)/((3000*.13+80)*(1+.13*1)))/√(1+.13)))*100

I get a different number than what excel gives me. The v开发者_运维问答alues I'm using are 3000$ owed, 13% interest, 80$ monthly payment. Excel and calculators online indicate 49 months (48.3 rounded up), but that formula gives me 39.4 months. Does anyone know of a java library I can implement in my code to perform calculations like this?

Thanks.


The arithmetic errors are probably because Java is using Integer math. Integer math completely disregards the decimal point by rounding down the value after each operation. Consider the following code:

int xInt = 5;
int yInt = (xInt/2) * 3;

double xDouble = 5;
double yDouble = (xDouble/2) * 3;

The resulting values of yInt and yDouble are different. yInt is 6 while yDouble is 7.5.

In your code you should convert the integer values to doubles or floats by appending decimal places. like this:

double val1 = (5/2)*3; // this equals 6, Don't do this
double val2 = (5.0/2.0)*3.0 // this equals 7.5, instead do this
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号