[SOLVED] separate number(price) with comma in javascript


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.


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

Answered By – Sandeepa

Answer Checked By – Terry (BugsFixing Volunteer)

Leave a Reply

Your email address will not be published. Required fields are marked *