Convert number into currency

The .toLocaleString is a method in the number prototype.

It accepts as first parameter IETF language tags (also called BCP 47 languag codes). More used ones are:

English:

  • en-US
  • en-GB English United Kingdom
  • en-CA English Canada
  • en-AU English Australia
  • en-IN English India

Spanish:

  • es-ES
  • es-MX
  • es-PE
  • es-AR

Others commonly seen:

  • ja-JP → Japanese Japan
  • ko-KR → Korean South Korea
  • ru-RU → Russian Russia
  • it-IT → Italian Italy
  • nl-NL → Dutch Netherlands
  • hi-IN → Hindi India
  • tr-TR → Turkish Turkey
const num = 1300
 
const currency = num.toLocaleString("es-PE", {
  style: "currency",
  currency: "PEN"
})
 
// -> "S/ 1,300.00"