-3
const renderCommas = (number) => {
    return number >= 1000 ? `${Number.parseFloat((number).toFixed(3))}` : number;
};
Hunter McMillen
  • 59,865
  • 24
  • 119
  • 170

2 Answers2

1

you can use toLocaleString()

a = 100000
console.log(a.toLocaleString());
McRist
  • 1,708
  • 11
  • 16
-3

You can use the following code to format a number with a comma:

var num       = 100000;
var formatted = num.toLocaleString(undefined);

console.log(formatted);
Grant Miller
  • 27,532
  • 16
  • 147
  • 165
ryan
  • 9
  • 2
  • 1
    I didn't downvote, but it's unclear to me why you're advocating for `undefined` as the parameter to `toLocaleString`, and I think without any explanation, it's an incomplete answer. – Dave Newton Aug 16 '18 at 20:03