Sunday, June 10, 2018

Jquery - Format number to 2 decimal places

Here is the below example for the discount calculation and get the value with 2 decimals.

$("#discount").change(function() {
    var list = $("#list").val();
    var discount = $("#discount").val();
    var price = $("#price");
    var temp = discount * list;
    var temp1 = list - temp;
    var total = temp1.toFixed(2);

    price.val(total);
});

No comments:

Post a Comment