Category: How do I do X?


This solution is summarized from an archived support forum post. This information may have changed. If you notice an error, please let us know in Discord.

How do I add comma’s in numbers?


I asked about how to add commas inside numbers using JavaScript. While .toLocaleString() function works for displaying numbers in different formats, it doesn't allow for input in localized format where decimal separators may differ. This is an issue for countries that use a comma instead of a period as the decimal separator. The problem is acknowledged by the team but has not yet been addressed.


The solution to add commas inside numbers in JavaScript is to use the .toLocaleString() function. This function can be used to transform a number into a localized format specific to a certain region or language. An example of converting a number into Indian rupee format and adding commas is shown in the code snippet:

var number = 123456.789;var formattedNumber = number.toLocaleString('en-IN');console.log(formattedNumber);

This code will output the number as "1,23,456.789" using the Indian rupee format.

However, this solution does not address the issue of inputting numbers in localized format, where the decimal separator is different for various regions. Currently, the decimal separator is hardcoded to ".", which can be an issue for countries that use "," as the decimal separator. This is an area where internationalization support in JavaScript is still pending.