0

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 values 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.

Evan R.
  • 1,210
  • 1
  • 27
  • 42

1 Answers1

1

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
slayton
  • 20,123
  • 10
  • 60
  • 89
  • i haven't done anything in java yet, I'm using a solver online and entering in the equation to match the formula that was provided in the other link. I may attempt to programmatically do the equation, but I'd like to make sure that I have the correct formula that matches what online financial calculators show. Having a Java library that has an NPER function would save me a huge amount of effort in doing this. – Evan R. Oct 03 '11 at 18:22
  • Looks like this works: http://www.ehow.com/how_2154015_calculate-term-investment-using-microsoft.html I just compared the results against the 2 online calculators and they match – Evan R. Oct 03 '11 at 18:49