JS number format

Problem

To format the number (120000) into (120,000) you have a simple built-in function in PHP number_format(). But you can't do that this simple in Javascript.

Solution

You can simply call the following Javascript function to format the number.

It accepts 4 parameters:

  1. The number that needs to be formatted.
  2. After how many digits the decimal will be placed.
  3. The decimal point symbol (default is "." dot)
  4. The thousand separator (default is "," comma)