LoginSignup
1
2

More than 5 years have passed since last update.

Numeral.jsで序数を得る

Last updated at Posted at 2017-09-20

順位表示などの国際化対応をする時に、日本語の場合だとn位のようにをつけるだけで問題ありません。
しかし英語の場合は1位は1st,2位は2ndのように序数を使用する必要があります。

このような場合には、数値のフォーマットや操作を行うNumeral.jsを使用するのが便利です。

例で上げたような序数を得るためのコードは次の通り。

var string = numeral(1).format('0o');
// '1st'

任意の数字の序数のサフィックスだけ欲しい場合は次のように書ける。

var ordinal = numeral.locales.en.ordinal(2)
// 'nd'
1
2
1

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
1
2