TV-C-15 TV-C-15 - 2 years ago 155
Javascript Question

Convert Excel math to JavaScript - trouble with ABS(Excel) to Modulus(JavaScript)

I have been converting an Excel spreadsheet to a JavaScript form all day.

It has gone pretty well. I have most of them working just fine.

I have been thrown by this one though:



My JavaScript conversion:

var calc = tax_per_year*(Math.pow((inflation - 0.015), (career_start-age)))*((1 - Math.pow(inflation, (%(career_start - age)))/(1 - inflation)));

It seems that JavaScript does not like the placement of the converted Excel "ABS" converted to JavaScript "%" Modulus

Am I using this modulus correctly here?
I have tried a variety of placements.

Answer Source

Using modulo in this scenario is wrong and makes no sense in this case. Modulo delivers you the rest of a division. Just use the javascript abs function.


Or have a look at the W3C Reference. Math.abs (W3C Reference)

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download