【发布时间】:2013-05-07 15:04:21
【问题描述】:
如果我有一个写成字符串的正整数,例如"three" 或"forty nine",有没有一种简单的方法可以将其转换为整数?
我很高兴使用语言学来转换另一种方式,但我从未尝试过这种方式!
【问题讨论】:
标签: ruby nlp linguistics
如果我有一个写成字符串的正整数,例如"three" 或"forty nine",有没有一种简单的方法可以将其转换为整数?
我很高兴使用语言学来转换另一种方式,但我从未尝试过这种方式!
【问题讨论】:
标签: ruby nlp linguistics
看看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
【讨论】: