Number to words

Hi all,
Is there a way to convert number to words in Ruby??

eg., if the number is 35764, then the word should be

Thirty Five Thousand Seven Hundred and Sixty Four

if it is 345 then Three Hundred and forty five.

Can any one please tell me the way to do??

Like any plugin or gems or any method available in ROR??

Naga harish Kanegolla wrote:

Is there a way to convert number to words in Ruby??
eg., if the number is 35764, then the word should be
Thirty Five Thousand Seven Hundred and Sixty Four
if it is 345 then Three Hundred and forty five.
Can any one please tell me the way to do??
Like any plugin or gems or any method available in ROR??

If I remember correctly there was a Ruby Q. that did just this. You
should be able to find it in the Ruby-talk archives or perhaps the
Pragmatic Programmer’s Best of Ruby Q. book.


Roderick van Domburg
http://www.nedforce.com

Roderick van Domburg wrote:

Naga harish Kanegolla wrote:

Is there a way to convert number to words in Ruby??
eg., if the number is 35764, then the word should be
Thirty Five Thousand Seven Hundred and Sixty Four
if it is 345 then Three Hundred and forty five.
Can any one please tell me the way to do??
Like any plugin or gems or any method available in ROR??

If I remember correctly there was a Ruby Q. that did just this. You
should be able to find it in the Ruby-talk archives or perhaps the
Pragmatic Programmer’s Best of Ruby Q. book.


Roderick van Domburg
http://www.nedforce.com

Hi,

This is an example used in Chris P.'s learn to program
http://pine.fm/LearnToProgram/?Chapter=08
(scroll down)

Roderick van Domburg wrote:

If I remember correctly there was a Ruby Q. that did just this. You
should be able to find it in the Ruby-talk archives or perhaps the
Pragmatic Programmer’s Best of Ruby Q. book.


Roderick van Domburg
http://www.nedforce.com

Yeah,
RubyQuiz used the same thing again a couple of weeks ago.
Equally, there’s a gem called “Linguistics” which happens to do this

require ‘Linguistics’
Linguistics.use(:en)

453.to_s.en.numwords => “four hundred and fifty-three”

On Sep 21, 2007, at 3:49 PM, Matthew R. wrote:

Yeah,
RubyQuiz used the same thing again a couple of weeks ago.
Equally, there’s a gem called “Linguistics” which happens to do this

require ‘Linguistics’
Linguistics.use(:en)

453.to_s.en.numwords => “four hundred and fifty-three”

Except that it should be written:
“four hundred fifty-three”

(i.e., without the “and”)

-Rob

Rob B. http://agileconsultingllc.com
[email protected]

Matthew R. wrote:

Roderick van Domburg wrote:

If I remember correctly there was a Ruby Q. that did just this. You
should be able to find it in the Ruby-talk archives or perhaps the
Pragmatic Programmer’s Best of Ruby Q. book.


Roderick van Domburg
http://www.nedforce.com

Yeah,
RubyQuiz used the same thing again a couple of weeks ago.
Equally, there’s a gem called “Linguistics” which happens to do this

require ‘Linguistics’
Linguistics.use(:en)

453.to_s.en.numwords => “four hundred and fifty-three”

Thanks a lot for all the good responses. I tried using the Linguistics
gem. But I have a small doubt.

Actually I am using this to convert the rupee number to word format. So
usually I used to print Rs 13,435.50 But this linguistic gem converted
into “thirteen thousand, four hundred and thirty-five point five”. It
looks annoying if its point five. Is there a option to exclude that
point five and insert “fifty paise” ??

Naga,

How about something like here
http://codersifu.blogspot.com/2007/08/mymoney-convert-money-to-word.html
I did it to convert money to word.

On Sep 22, 4:57 am, Rob B. [email protected]

Try num2en plugin,
svn export http://svn.creopolis.com/num_to_english/trunk
made by Elad, (http://pandejo.blogspot.com/)
if you want it multilanguaged you’ll need to work some… :slight_smile:

http://www.yulia-site.org

On 9/22/07, Naga harish Kanegolla [email protected]
wrote:

point five and insert “fifty paise” ??

you could try something like
def currency_to_word(amount)
currency = amount.to_s.split(/./)
currency[0].en.numwords + " rupee and " + currency[1].en.numwords +
" paise"
end