TV-C-15 - 6 months ago 26

Javascript Question

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:

**EXCEL FORMULA:**

`G20*((G33-0.015)^(G17-G16))*((1-G33^(ABS(G17-G16)))/(1-G33))))`

`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

I have tried a variety of placements.

Answer

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.

```
Math.abs(<your_value>);
```

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

Source (Stackoverflow)

Comments