xFlowDev
xFlowDev

Reputation: 205

Show price with two digits after comma

I'm trying to show a price, calculated from two input fields, with two digit after the comma. So far I got this:

var lAnzahl = 0;
$("#ArtikelTabelle > tbody").on("keyup", "tr > td > input.anzahl", function () {
    lAnzahl = $(".anzahl").val();
});

var lPreis = 0;
$("#ArtikelTabelle > tbody").on("keyup", "tr > td > input.preis", function () {
    var aa = $(".preis").val();
    var bb = aa.replace(",", ".");
    lPreis = parseFloat(bb);

});

$("#ArtikelTabelle > tbody").on("keyup", "tr > td > input.preis ,tr > td > input.anzahl ", function () {
    var lGesamt = lAnzahl * lPreis;
    var lAusgabe = lGesamt.toString().replace(".", ",");
    $("#gesamtpreis").empty();
    $("#gesamtpreis").append(": " + lAusgabe + "€");
    lGesamt = 0;
    lAusgabe = 0;
    });

I already get lGesamt calculated properly but it displays like this: 12,3 €
How can I add the 0 to the second decimal place or restrict it to show only two decimal places ?

Upvotes: 0

Views: 902

Answers (1)

Oleksandr T.
Oleksandr T.

Reputation: 77482

There is method toFixed

(lGesamt).toFixed(2)

Upvotes: 3

Related Questions