【问题标题】:How do I convert words to their equivalent number?如何将单词转换为等效数字?
【发布时间】:2013-05-07 15:04:21
【问题描述】:

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

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

【问题讨论】:

    标签: ruby nlp linguistics


    【解决方案1】:

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

    【讨论】:

    • 我很难直截了当地告诉我的老板我是在打压输出。
    • 这看起来是一个有用的项目。
    • 当我和老板讨论这个问题时,我的脸一点也不直。
    猜你喜欢
    • 1970-01-01
    • 2016-07-12
    • 1970-01-01
    • 1970-01-01
    • 2012-08-04
    相关资源
    最近更新 更多