4

"three"またはなどの文字列として正の整数を記述した場合"forty nine"、これを整数に変換する簡単な方法はありますか?

言語学を使用して別の方法で変換できることには満足していますが、この方法を試したことはありません!

4

1 に答える 1

6

numbers_in_words GitHub プロジェクトを見てください。少なくとも英語の数字の文字列については、探している機能を提供しているようです。

プロジェクトのドキュメントから:

require 'numbers_in_words'
require 'numbers_in_words/duck_punch'

112.in_words
#=> one hundred and twelve

"Seventy million, five-hundred and fifty six thousand point eight nine three".in_numbers
#=> 70556000.893
于 2013-05-07T15:43:45.170 に答える