Breaking down a long math calculation

What does the exl function look like?

see post #3, there is no exl() function.

Then the example expression as posted is missing a delimiter or operator of some sort no?

At least the syntax looks off to me.

What is the value of the exl variable?

I’m not seeing it in the pastebin code.

I’d say it’s the execllentPercent variable in PasteBin

Ah, yes, I think you’re right.

As Math.pow() takes 2 parameters - base and exponent - I think the problem is here
1 + exl(Months,0-returnAmount,amount,0) i.e.
the commas should be operators (+, -, /, *, etc) and there should also be one between exl and the parenthesized variables.

What they should be, I’m sorry to say, I have no idea

@Mittineague the exl is variable i changed later in pastebin, sorry should have updated before.

That is a numeric result - computers use that format for very huge numbers and very small numbers - the number after the e is the number of places to move the decimal point in the number before the e - the 79 means move the decimal point 79 places to the right in the number before the e to get the answer.

1 Like

If it helps, here’s a jsfiddle I put together using an APR function from an APR formula article.

The jsfiddle that you can play with is at http://jsfiddle.net/pmw57/q0x47by2/

@Paul_Wilkins it make sense, thanks. But APR result is for fixed and It doesn’t show. How does one take APR percentage from the result.

That can be adjusted quite easily, by changing the following returned value:

return testrate.toFixed(6);

What doesn’t show? The result?

The resulting value is your APR percentage. For example 0.056034 is the same as 5.6034%

@Paul_Wilkins , so here is my code. I hope i am correct? If so how do i convert that value to percentage?

Currently your code shows the total repayable amount of money. I think that it will help if you can explain to me how that relates to the percentage that you seem to desire.

@Paul_Wilkins I don’t know how APR are calculated. Is it the total repayable amount that is applied for APR or just your input amount you put (without any percentages) etc. Although your code shows and explain, what is being computed but suppose if that is what i am getting. How do get the APR in terms of percentage? In short, i want the total repayable amount and other variables that i have computed or entered by user to calculate percentage of APR on that. like you quoted For example 0.056034 is the same as 5.6034%

Well, when you have the percentage, such as 0.056034, you multiply it by 100 to end up with a visual representation of the percentage, that being 5.6034%

For example,

var aprRate = 0.056034,
    aprPercentage = Math.toFixed(aprRate * 100, 2) + '%';

@Paul_Wilkins sorry to sound so noob, whats the ,2 for and what does comma (,) do in javascript?, plus when i do Math.Fixed(), it says its not a function?

The comma 2 is for a second parameter to the toFixed function, specifying to how many decimal places we want our final percentage value to be shown as.

The Fixed() part has been fixed to be toFixed() instead, no pun intended.

@Paul_Wilkins when i do

aprPrecentage = Math.toFixed(totalRepayable * 100,2);

it says Math.toFixed is not a function, i seen it before, why does it take () as function and variable in it as function args?

Ahh, my bad on that, it was late sorry. The following will work for you, assuming that totalRate is a percentage in decimal form.

totalRate = 0.0564545435;
aprPrecentage = (totalRate * 100).toFixed(2);

There are a few different ways of using it. The toFixed function is a part of the Number object. The toFixed function gives a string version of the number, so that some formatting can be applied. The argument that you give to toFixed says to how many decimal places the string version of should be shown as.

@Paul_Wilkins I get a seriously big amount. like 125789.60%, shouldn’t be the APR just something atmost like 5.99%, i mean the value such big is like a APR rip off. lol

what is the current APR calculation you use?