[javascript] How to format numbers?

You may want to consider using toLocaleString()

Working Example:

_x000D_
_x000D_
const number = 1234567890.123;

console.log(number.toLocaleString('en-US')); // US format

console.log(number.toLocaleString('en-IN')); // Indian format
_x000D_
_x000D_
_x000D_

Tested in Chrome v60 and v88

Source: Number.prototype.toLocaleString() | MDN