Reputation: 903
I need format a decimal number on JavaScript, my number are returning 100.000 but I want 100,00.
var val = 100.0000;
console.log(val);
// do something
console.log(val);
what I get: 100.0000
what I expected: 100,00
what I need to do for made this?
Upvotes: 0
Views: 65
Reputation: 386846
It depends on the need. I suggest to have a look to the formatting methods of Number.prototype.toLocaleString
.
var val = 100.0000;
document.write(val.toLocaleString('de-DE', { maximumFractionDigits: 2, minimumFractionDigits: 2}));
Upvotes: 0
Reputation: 5971
One possible solution:
parseFloat(val).toFixed(2).replace('.', ',');
See in action: JSFiddle
Upvotes: 2