DEV Community

@kon_yu
@kon_yu

Posted on

2 2

How to create a string of numbers with , $, €, or £ in JavaScript.

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
Enter fullscreen mode Exit fullscreen mode

U.S. dollar

const price = 1234567890.1234
const usd = price.toLocaleString('US',
  { style: 'currency', currency: 'USD',})

console.log(usd)
// => $1,234,567,890.12"
Enter fullscreen mode Exit fullscreen mode

Euro

const price = 1234567890.1234
const eur = price.toLocaleString('DE',
  { style: 'currency', currency: 'EUR' })
console.log(eur)
//=> 1.234.567.890,12 €
Enter fullscreen mode Exit fullscreen mode

British pound

const pond = price.toLocaleString('GB',
  { style: 'currency', currency: 'GBP',})
console.log(pond)
//=> "£1,234,567,890.12"
Enter fullscreen mode Exit fullscreen mode

Hostinger image

Get n8n VPS hosting 3x cheaper than a cloud solution

Get fast, easy, secure n8n VPS hosting from $4.99/mo at Hostinger. Automate any workflow using a pre-installed n8n application and no-code customization.

Start now

Top comments (0)

SurveyJS custom survey software

JavaScript UI Libraries for Surveys and Forms

SurveyJS lets you build a JSON-based form management system that integrates with any backend, giving you full control over your data and no user limits. Includes support for custom question types, skip logic, integrated CCS editor, PDF export, real-time analytics & more.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay