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)