2
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

JavaScriptで数値から¥, $, €, £を付けた文字列を作る

Last updated at Posted at 2020-09-11

JavaScriptで金額を表す文字列に通貨の記号やカンマで区切りをつけて表示するにはtoLocaleStringを用いる

ref: toLocaleStringの仕様 https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toLocaleString

日本円の場合

const price = 1234567890.1234
const jpy = price.toLocaleString('JP',
  { style: 'currency', currency: 'JPY' })

console.log(jpy)
// => ¥1,234,567,890

米ドルの場合

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

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

ユーロの場合

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

英ポンドの場合

const pond = price.toLocaleString('GB',
  { style: 'currency', currency: 'GBP',})
console.log(pond)
//=> "£1,234,567,890.12"
2
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?