Convert string numbers( in word format) to integer ruby

后端 未结 4 2050
没有蜡笔的小新
没有蜡笔的小新 2021-01-24 18:43

If you have a string ten, is it possible to convert it to an integer 10 in Ruby? (maybe in rails?)

I value the developers at tryruby.org, and i

4条回答
  •  情书的邮戳
    2021-01-24 19:07

    Check out this gem for handling word to number conversions.

    From the readme:

    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
    

提交回复
热议问题