3-digit delimited comma

I would like to know how to output a number set in a numeric field with a comma separating the three digits.

Hello @ishizaka

Thanks for reaching out. Good question. You can use the following code, it can help you.

var number = {{ module.number_field }};document.body.innerHTML = number.toLocaleString();// 1,557,564,534

Hello @ishizaka

Thanks for reaching out. Good question. You can use the following code, it can help you.

var number = {{ module.number_field }};document.body.innerHTML = number.toLocaleString();// 1,557,564,534

Hello @ishizaka

To output a number with a comma separating the thousands, you can use the toLocaleString() method in JavaScript.

Here’s an example:

const number = 1234567.89;
const formattedNumber = number.toLocaleString(); // "1,234,567.89"

The toLocaleString() method formats the number according to the locale and options specified, so the output may vary depending on the user’s language and region settings.

You can also specify the locale explicitly, like this:

const number = 1234567.89;
const formattedNumber = number.toLocaleString('en-US'); // "1,234,567.89"

In this example, 'en-US' specifies the locale as English (United States).

If you want to use a different character as the delimiter, you can specify it as an option:

const number = 1234567.89;
const options = { 
 useGrouping: true, 
 minimumFractionDigits: 2, 
 maximumFractionDigits: 2, 
 minimumIntegerDigits: 1, 
 style: 'currency', 
 currency: 'USD',
 currencyDisplay: 'symbol',
 numberingSystem: 'latn', // use latin digits
 notation: 'compact',
 compactDisplay: 'short',
 signDisplay: 'auto' 
};
const formattedNumber = number.toLocaleString('en-US', options); // "$1.2M"

In this example, the options object specifies various options for formatting the number, including useGrouping: true to enable grouping with a comma delimiter. The currency option is set to 'USD' to format the number as a US dollar currency value.

You can adjust the options to format the number according to your specific needs.