Home > Enterprise >  How do I format numbers as decimals in NextJS
How do I format numbers as decimals in NextJS

Time:02-12

I'm working on a basic website using NextJS, my code is like this

products: [
 {
   brand: 'example',
   price: 10000,
 },
...
],

How do I change the 10000 to 10,000.

CodePudding user response:

You can use toLocaleString() to format the number with commas like this:

var a = 10000000;
console.log(a.toLocaleString())

var obj = {products: [
 {
   brand: 'example',
   price: 10000,
 }
]
}

obj.products[0].price = obj.products[0].price.toLocaleString()

console.log(obj)

  • Related