Jarla Jarla - 1 month ago 5
jQuery Question

How can I convert a number into a comma seperated decimal number?

I want to convert the number 64.6 into 64,60.

var number = 64.6

var a = parseInt(number);
var b = a.toFixed(2);
var c = b.toString().replace(/\./g, ',');
$(".result").html(c);


But with my code, the result is 64,00.

Answer

You can use parseFloat as noted by BenG.

var number = 64.6

var a = parseFloat(number);
var b = a.toFixed(2);
var c = b.toString().replace(/\./g, ',');

console.log(c);