Search code examples
jquerydecimaltofixed

Jquery Calculator Decimal Point


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.


Solution

  • 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