To display a string of money in JavaScript with a comma, use the toLocaleString
method.
ref: toLocaleString specification: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toLocaleString
Japanese Yen
const price = 1234567890.1234
const jpy = price.toLocaleString('JP',
{ style: 'currency', currency: 'JPY' })
console.log(jpy)
// => ¥1,234,567,890
U.S. dollar
const price = 1234567890.1234
const usd = price.toLocaleString('US',
{ style: 'currency', currency: 'USD',})
console.log(usd)
// => $1,234,567,890.12"
Euro
const price = 1234567890.1234
const eur = price.toLocaleString('DE',
{ style: 'currency', currency: 'EUR' })
console.log(eur)
//=> 1.234.567.890,12 €
British pound
const pond = price.toLocaleString('GB',
{ style: 'currency', currency: 'GBP',})
console.log(pond)
//=> "£1,234,567,890.12"
Top comments (0)