I made a calculator and it is showing result in many decimal places. How can i restrict it to just two decimal places.
I tried using .tofixed(3) but it is not working.
Working Fiddle: http://jsfiddle.net/m3hfb37x/
I made a calculator and it is showing result in many decimal places. How can i restrict it to just two decimal places.
I tried using .tofixed(3) but it is not working.
Working Fiddle: http://jsfiddle.net/m3hfb37x/
Try .toFixed(2).
Note that it's 2 (ie, two decimal places) where as your example had 3 for some reason.
Also note the capital F in toFixed. Your example shows a lowercased one which would have resulted in an error.
Changing just this line
$('#amount').text("$" + result_maker);
to
$('#amount').text("$" + result_maker.toFixed(2));
worked for me.