22
17

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 5 years have passed since last update.

数字の3ケタごとに「,(カンマ)」を付ける【JavaScript】

Last updated at Posted at 2014-12-05

「1000000円」を「1,000,000円」といった感じに、価格の表示などで3ケタごとに「,(カンマ)」付けたいことってよくありますよね。

3ケタごとにカンマを付けるのは若干ややこしいのですが、
便利なtoLocaleStringメソッドがありました。


var num = 123456789
num.toLocaleString()

num123,456,789となる

※SafariやOpera、古いブラウザは対応していないものもあるので注意してください。

【参考】
JavaScriptの数値をカンマ区切りにする最も簡単な方法 | while(isプログラマ)

22
17
3

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
22
17

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?