LoginSignup
4
3

More than 5 years have passed since last update.

Numeral.js で通貨記号を変更する

Posted at

Numeral.js で Currency フォーマット時の通貨記号を変更する方法のメモ。

参考記事の通りにロケールの変更するだけで良かったので簡単だった。
試したバージョンは numeral@2.0.6

> const numeral = require('numeral');
// locale ファイルの読み込み
> require('numeral/locales/ja');
> require('numeral/locales/de');

// locale を ja に変更
> numeral.locale();
'ja'
> numeral(999999999).format('$0,0');
'¥999,999,999'

// locale を de に変更
> numeral.locale('de');
'de'
> numeral(999999999).format('$0,0');
'€999 999 999'

// locale をデフォルトに戻すには en を指定。en は locale ファイルを読み込む必要無し
> numeral.locale('en');
'en'
> numeral(999999999).format('$0,0');
'$999,999,999'

参考

JavaScriptでカンマ区切りなどによる数値のフォーマットができるNumeral.jsが便利 - Qiita
http://qiita.com/ariarijp/items/4a043c60ca00d848af48

Numeral.jsのlocaleを変更して桁区切り文字をカンマからピリオドにする - dackdive's blog
http://dackdive.hateblo.jp/entry/2017/05/24/185346

4
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
4
3