Search code examples
jquerymathnumbersdollar-sign

jQuery math returns 0.0 but 0.00 is required


I have the following function:

function checktotal(){
    total = currentproduct["priceperticket"] * $("#qtyselect").val();
    $("span#totalprice").html("$"+total);
}

and when it has a total of 65.50 it returns 65.5.

I don't know if I need to do a length or split at the . and then join a 0 or what to do.


Solution

  • Use 'toFixed' method:

    $("span#totalprice").html("$"+total.toFixed(2));