Jquery Calculator Decimal Point

1.6k Views Asked by At

I have been trying to work out for the last day how to add a decimal point onto the total of my calculator.

http://www.waveleisure.co.uk/calc/

Its probably best to check out that link, the monthly saving works but I cant seem to get the price to format in .00 .

The script is here, (http://www.waveleisure.co.uk/calc/js/myscript.js) its a modified version of one i found online? Any ideas, I have tried toFixed(4); to no avail.

Thanks.

2

There are 2 best solutions below

1
On BEST ANSWER

Try adding

var total = (+aaa + +bbb + +ccc).toFixed(2);
$("#total").val(total);

after lines 116, 184 and 253 in myscript.js and replace all instances where you have

Math.round((+aaa + +bbb + +ccc) *4 - value).toFixed(2);

with

((aaa + +bbb + +ccc) *4 - value).toFixed(2)

of course replacing value with the original constant in the code

3
On

In your code you are rounding off the answer

// Total Saving Scriptt
var savingchoice = Math.round((+aaa + +bbb + +ccc) *4 - 41).toFixed(2);

Change this to

var savingchoice = ((aaa + +bbb + +ccc) *4 - 41).toFixed(2);

Math.round rounds to nearest Integer value, so you will lose digits after decimal value.