FrontendDeveloper.in

JavaScript question detail

How do you print numbers with commas as thousand separators

You can use the Number.prototype.toLocaleString() method which returns a string with a language-sensitive representation such as thousand separator, currency etc. of this number.

function convertToThousandFormat(x) {
return x.toLocaleString(); // 12,345.679
}

console.log(convertToThousandFormat(12345.6789));
Back to all JavaScript questions
Get LinkedIn Premium at Rs 399