In React, how to format a number with commas?

Print a number with commas as thousands separators in JavaScript

You can find a general JS solution for this:


toLocaleString:

// A more complex example: 
number.toLocaleString(); // "1,234,567,890"

// A more complex example: 
var number2 = 1234.56789; // floating point example
number2.toLocaleString(undefined, {maximumFractionDigits:2}) // "1,234.57"

NumberFormat (Safari not supported):

var nf = new Intl.NumberFormat();
nf.format(number); // "1,234,567,890"

source: https://stackoverflow.com/a/32154217/6200607


var number = 1234567890; // Example number to be converted

⚠ Mind that javascript has a maximum integer value of 9007199254740991


Other Solution:

Put Comma Values in Numbers

2345643.00 will return 2,345,643.00

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)