Link to home
Start Free TrialLog in
Avatar of turtleman2009
turtleman2009

asked on

Javascript Calculator

I have this calculator: http://johnbarban.com/calculator/adonis.html the problem is that I need the results to only show 2 decimal places. Could someone show me what code I would use to make this happen?

Thanks
Avatar of Brad Howe
Brad Howe
Flag of Canada image

Can you use the function Number.toFixed(x)

It formats any number for "x" number of trailing decimals. The number is rounded up, and "0"s are used after the decimal point if needed to create the desired decimal length.

eg:
      idealwaist.toFixed(2)

Cheers,
Hades666
Avatar of turtleman2009
turtleman2009

ASKER

I just tried your solution and I could not get it to work, this is how I applied it:

document.getElementById('adonisidealwaist').innerHTML = idealwaist.toFixed(2);

Did I do it incorrectly?
ASKER CERTIFIED SOLUTION
Avatar of Brad Howe
Brad Howe
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hmm,

I am still having trouble with this.

When I use this code it completely stops calculating.

Any thoughts?
It worked after all, it was just on my local machine that it wasn't working