how to format numbers javascript code example
Example 1: how to number format in javascript
function formatNumber(num) {
return num.toString().replace(/(\d)(?=(\d{3})+(?!\d))/g, '$1,')
}
console.info(formatNumber(2665))
console.info(formatNumber(102665))
console.info(formatNumber(111102665))
console.info(formatNumber(1240.5))
console.info(formatNumber(1000240.5))
Example 2: javascript format price
const number = 123456.789;
console.log(new Intl.NumberFormat('ja-JP', {
style: 'currency',
currency: 'BWP',
}).format(number));