0

Currently I'm working on a Shopping cart project using NodeJs with MongoDB as backend.

I have already grab the item total to the checkout page, but I need the figure to be displayed using commas as each 3 digit passing from left side.

for example. 70000 should be printed as 70,000 and 1400000 should be printed as 1,400,000.

Sivaprasad
  • 119
  • 10

2 Answers2

1

I suggest using Numeral.js: http://numeraljs.com/ This package handles numbers nicely.

MattB
  • 1,104
  • 8
  • 15
1

Number.prototype.toLocaleString() works well for most cases. You can read more here.

var number = 3500;

console.log(number.toLocaleString());
// Displays "3,500" if in U.S. English locale
andersryanc
  • 939
  • 7
  • 19