Javascript Calculator

I have this calculator: 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?

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Brad HoweDevOps ManagerCommented:
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.


turtleman2009Author Commented:
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?
Brad HoweDevOps ManagerCommented:
Sorry correction. Just looked at your could and you are using floats.

var water = weight * 0.025;

//Add the following formatters      

idealwaist = parseFloat(idealwaist).toFixed(2);
idealshoulders = parseFloat(idealshoulders).toFixed(2);
hips = parseFloat(hips).toFixed(2);
maxloss = parseFloat(maxloss).toFixed(2);
water = parseFloat(water).toFixed(2);


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
turtleman2009Author Commented:

I am still having trouble with this.

When I use this code it completely stops calculating.

Any thoughts?
turtleman2009Author Commented:
It worked after all, it was just on my local machine that it wasn't working
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.