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
Best Way to Highlight Current Page in Rails 3? - Apply a CSS Class to Links Conditionally
Simple Way of Turning Off Observers During Rake Task
Why Did Matz Choose to Make Strings Mutable by Default in Ruby
Get Single Char from Console Immediately
When Would a Ruby Flip-Flop Be Useful
Activerecord::Adapternotspecified Database Configuration Does Not Specify Adapter
Peer-To-Peer File Sharing with Web Sockets
How to Install Ruby 2 on Ubuntu Without Rvm
A Copy of Xxx Has Been Removed from the Module Tree But Is Still Active
Os X Mountain Lion: Gcc-4.2 No Such File or Directory
Gem.Source_Index Is Deprecated, Use Specification. Should I Re-Install Gem or Rails
How to Select Every Nth Item in an Array
How to Add Migration with Multiple References to the Same Model in One Table? Ruby/Rails
Is There an Expect Equivalent Gem for Ruby
Ruby on Rails Rake Assets:Precompile Error
Why Do I Get a Bcrypt-Ruby Gem Install Error
Is There Goto Statement in Ruby
How to Install Rvm System Requirements Without Giving Sudo Access for Rvm User