将数字转换为单词的简单方法

时间:2016-05-17 11:01:33

标签: ruby

1转换为"first"2"second"等的简单方法是什么?即使它是图书馆或宝石,任何建议都会有所帮助。

2 个答案:

答案 0 :(得分:3)

My favorite is to use the twitter_cldr gem.

require "twitter_cldr"
1.localize(:en).to_rbnf_s("SpelloutRules", "spellout-ordinal") # => "first"
2.localize(:en).to_rbnf_s("SpelloutRules", "spellout-ordinal") # => "second"

答案 1 :(得分:1)

我只知道active_support的ordinalize。以下示例生成第1个,第2个,第3个,这与提出的问题不完全相同。

1.ordinalize # returns "1st"
2.ordinalize # returns "2nd"
相关问题