Ruby: Convert Number to Words (Numerical)

Recently I’ve published my new gem NumberToWords. This plugin/gem will override Ruby’s Numeric class adding a new method called to_words. For now, it only works for Spanish.

Sample usage:

require 'rubygems'
require 'number_to_words'
5678.to_words
=> cinco mil seiscientos setenta y ocho”

Another common usage is for describing currency quantities:

number = 4567.90
=> 4567.9
number.to_words.capitalize << ' pesos ' << (number.to_s.split('.')[1] || 0).rjust(2,'0')
=> "Cuatro mil quinientos sesenta y siete pesos 09/100 M.N."

http://github.com/mexpolk/number_to_words/tree/master

Happy Hacking!

Advertisements
Ruby: Convert Number to Words (Numerical)

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s