Format a number with commas using JavaScript
Posted by SceDev
Last Updated: February 17, 2024

Write a javascript program that format a number with commas.

const formatNumber = x => x ? x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",") : 0;

console.log(formatNumber(50000000.99));