Why Is The Decimal Value Not Showing?
So i have my jQuery script ready, but i am struggling with 1 problem , if a value is: $ 10 then everything is fine, but when a value is: $24,99 then it only will show 24 instead of
Solution 1:
you have to change the decimal separator to dot and parseInt
to parseFloat
var unitAmount = parseFloat($input.parent().prev().text().replace("$", "").replace(",","."))
And after arithmetic operations you have to convert you number back to a string and replace the dot with ,
:
$input.parent().next().text("€ " + (""+total).replace(".",","));
For tatal price:
var total = 0;
$("tbody tr td:last-child").each(function() {
total += parseFloat($(this).text().replace("€","").replace(",",".") || 0);
});
$("#total").html( (""+total).replace(".",","));
The full demo is here
Solution 2:
It is happening because you have used parseInt
, use parseFloat
.
Secondly, value 22,95
should be 22.95
.
var unitAmount = parseFloat($input.parent().prev().text().replace("$", ""));
total += parseFloat($(this).text().replace("€","") || 0);
Solution 3:
$input.parent().next().text(total > 0 ? ("€ "+total).replace(".",",") : "");
This should work and you will see , instead of .
Solution 4:
Because you are using parseInt, use parseFloat instead
Post a Comment for "Why Is The Decimal Value Not Showing?"