Juan Ignacio
Juan Ignacio

Reputation: 3267

JavaScript Math formula result

With help of others stackers I converted this Excel formula

=+G15*B15/(1-(1+G15)^(-H15))

into this javascript formula (given that G15=1.325%, B15=importe and H=plazo):

(importe * 0.01325) / (1 - (Math.pow((1 + importe), -plazo) ) );

Now, when in excel and javascript I calculate importe=10000 and plazo=144, in excel I get 155.93 and in javascript I get 132.5

I've been over this and lots of other formulas too much and there may be some silly mistake but I can't see... like reading a misspelled word you wrote and not spotting the typo.

Thanks in advance

Upvotes: 0

Views: 209

Answers (3)

micadelli
micadelli

Reputation: 2482

This is your desired calculation:
=+G15*B15/(1-(1+G15)^(-H15))
and instead of using your example of converted code:
(importe * 0.01325) / (1 - (Math.pow((1 + importe), -plazo) ) ) that is equivalent of:

=B15*G15/(1-(1+B15)^(-H15))

so your formula should be:

(0.01325 * importe) / (1 - (Math.pow((1 + 0.01325), -plazo)));

Upvotes: 1

Andreas
Andreas

Reputation: 21881

10001 ^ -144 = 9.857038937816808015251426789861755167080725836 × 10^-577

The result can't be representated correctly and will be "truncated" to 0. 132.5 equals to (importe * 0.01325)

The Complete Javascript Number Reference

Upvotes: 0

kevin628
kevin628

Reputation: 3526

Try putting parentheses around the G15*B15 in your excel formula and see if the answers match or not.

Upvotes: 0

Related Questions