1

For price of product i have this format : 1200000.

I want change format to become : 1,200,000.

The example :

var price = 12000;
// the price become this: 
var price1 = 12,000;

Insert the comma must start in end of number.

sajadsholi
  • 153
  • 1
  • 1
  • 10
  • 3
    Possible duplicate of [How to print a number with commas as thousands separators in JavaScript](https://stackoverflow.com/questions/2901102/how-to-print-a-number-with-commas-as-thousands-separators-in-javascript) – Ana Liza Pandac Dec 24 '18 at 15:26

1 Answers1

0

You can use the toLocaleString method format numbers according to the users locale, or to a locale of your specification:

var price = 1200000;
console.log(price.toLocaleString()); //formats to the user's locale
console.log(price.toLocaleString('es-ES') //format as Spanish
Andru
  • 6,819
  • 3
  • 20
  • 25
Sandeepa
  • 3,052
  • 5
  • 22
  • 38
  • @sajadsholi refer this link for browser support, https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toLocaleString#Browser_compatibility – Sandeepa Dec 24 '18 at 15:54