Using Ruby Convert Numbers to Words

Number to English Word Conversion Rails

No, you have to write a function yourself. The closest thing to what you want is number_to_human, but that does not convert 1 to One.

Here are some URLs that may be helpful:

  • http://codesnippets.joyent.com/posts/show/447
  • http://raveendran.wordpress.com/2009/05/29/ruby-convert-number-to-english-word/
  • http://deveiate.org/projects/Linguistics/

Convert string numbers( in word format) to integer ruby

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

Easy way to convert numbers into ordinals in words

My favorite is to use the twitter_cldr gem.

require "twitter_cldr"
1.localize(:en).to_rbnf_s("SpelloutRules", "spellout-ordinal") # => "first"
2.localize(:en).to_rbnf_s("SpelloutRules", "spellout-ordinal") # => "second"

English words (ONE, TWO, THREE) to number(1,2,3) in ruby

I created a hash up-to twenty for all words and only for tens(thirty, forty, fifty etc.). Using Reg-ex took off two words and added them for example twenty two is addition of 20+2=22; right now my script only works till hundred, but it can be extended for numbers over 100 and so on.



Related Topics



Leave a reply



Submit