繁体   English   中英

如何将单词转换成它们的等值数字?

[英]How do I convert words to their equivalent number?

如果我有一个写为字符串的正整数,例如"three""forty nine" ,是否有一种简单的方法可以将其转换为整数?

我很高兴使用语言学来进行另一种转换,但是我从未尝试过这种方法!

看一下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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM