Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > convert number to english word

Reply
Thread Tools

convert number to english word

 
 
Vetrivel Vetrivel
Guest
Posts: n/a
 
      03-31-2009

How to convert number to word.
Ex
8
eight
555
five hundered and fiftyfive
--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
 
 
 
James Gray
Guest
Posts: n/a
 
      03-31-2009
On Mar 31, 2009, at 11:26 AM, Vetrivel Vetrivel wrote:

> How to convert number to word.
> Ex
> 8
> eight
> 555
> five hundered and fiftyfive


Check the solutions to this old Ruby Quiz:

http://rubyquiz.com/quiz25.html

James Edward Gray II

 
Reply With Quote
 
 
 
 
Vetrivel Vetrivel
Guest
Posts: n/a
 
      03-31-2009
James Gray wrote:
> On Mar 31, 2009, at 11:26 AM, Vetrivel Vetrivel wrote:
>
>> How to convert number to word.
>> Ex
>> 8
>> eight
>> 555
>> five hundered and fiftyfive

>
> Check the solutions to this old Ruby Quiz:
>
> http://rubyquiz.com/quiz25.html
>
> James Edward Gray II



I need Ruby Module to use this...
--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
Loga Ganesan
Guest
Posts: n/a
 
      04-04-2009
Vetrivel Vetrivel wrote:
> James Gray wrote:
>> On Mar 31, 2009, at 11:26 AM, Vetrivel Vetrivel wrote:
>>
>>> How to convert number to word.
>>> Ex
>>> 8
>>> eight
>>> 555
>>> five hundered and fiftyfive

>>
>> Check the solutions to this old Ruby Quiz:
>>
>> http://rubyquiz.com/quiz25.html
>>
>> James Edward Gray II

>
>
> I need Ruby Module to use this...


Refer this URL:
http://refactormycode.com/codes/628-...mbers-to-words

There is a module called linguistics in ruby to do that.
--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
trans
Guest
Posts: n/a
 
      04-04-2009


On Mar 31, 12:26=A0pm, Vetrivel Vetrivel <(E-Mail Removed)>
wrote:
> How to convert number to word.
> Ex
> =A0 =A0 =A0 =A08
> eight
> =A0 =A0 =A0 =A0 =A0 =A0555
> five =A0hundered and fiftyfive


Check out the <a href=3D"http://english.rubygorge.org">English</a> gem
too.

T.

 
Reply With Quote
 
Nobuhiro IMAI
Guest
Posts: n/a
 
      04-04-2009
Hello,

On Wed, Apr 1, 2009 at 1:26 AM, Vetrivel Vetrivel
<(E-Mail Removed)> wrote:
>
> How to convert number to word.
> Ex
> =A0 =A0 =A0 8
> eight
> =A0 =A0 =A0 =A0 =A0 555
> five =A0hundered and fiftyfive


Integer#to_alphabetic from
http://github.com/technohippy/ordina...bject/tree/ma=
ster
sounds nice for me .
--=20
Nobuhiro IMAI

 
Reply With Quote
 
jazzez ravi
Guest
Posts: n/a
 
      04-06-2009
Hi Vetrivel,

try this ..


class Fixnum

def english_word
@h = {0=>"zero", 1=>"One", 2=>"Two", 3=>"Three", 4=>"Four", 5=>"Five",
6=>"six", 7=>"seven", 8=>"Eight",
9=>"Nine",10=>"Ten",11=>"Eleven",12=>"Twelve",13=> "Thirteen",14=>"Fourteen",15=>"Fifteen",16=>"Sixte en",17=>"Seventeen",18=>"Eighteen",19=>"Nineteen", 20=>"Twenty",30=>"Thirty",40=>"Fourty",50=>"Fifty" ,60=>"Sixty",70=>"Seventy",80=>"Eighty",90=>"Ninty "}
@i=0
@array=[]
@result=""
if self > 99
str_num=self.to_s #@num.to_s
str_num_len=str_num.length
str_full_num=str_num.insert(0,"0"*(11-str_num_len))
str_full_num=str_num.insert(8,"0")
str_full_num.scan(/../) { |x| @array<<x }
6.times do
self.def_calc
@i+=1
end
else
if self > 9
puts
(self.proc_double_dig((self/10)*10))+(self.proc_single_dig(self%10))
else
if self > 0
puts self.proc_single_dig(self)
else
return "AMOUNT NOT KNOWN or NILL"
end
end
end
end


def def_calc
case @i
when 0
str=self.proc_unit(@array[@i])
if (str.scan(/\w+/)).length!=0
then str=str+ "hundred & "
@result=@result+str
end
when 1
str=self.proc_unit(@array[@i])
if (str.scan(/\w+/)).length!=0
then str=str+ " Crore, "
@result=@result+str
end
when 2
str=self.proc_unit(@array[@i])
if (str.scan(/\w+/)).length!=0
then str=str+ " Lakh, "
@result=@result+str
end
when 3
str=self.proc_unit(@array[@i])
if (str.scan(/\w+/)).length!=0
then str=str+ " Thousand, "
@result=@result+str
end
when 4
str=self.proc_unit(@array[@i])
if (str.scan(/\w+/)).length!=0
then str=str+ " Hundred, "
@result=@result+str
end
when 5
str=self.proc_unit(@array[@i])
if (str.scan(/\w+/)).length!=0
then str=str+ ". "
@result=@result+str
end
print @result.sub(/..$/,"")
else
end
end

def proc_unit(x)
if x.to_i>0
if x.to_i<=10
return self.proc_single_dig(x.to_i)
else
if x.to_i<=20
return self.proc_double_dig(x.to_i)
else
return
(self.proc_double_dig((x.to_i/10)*10))+(self.proc_single_dig(x.to_i%10))
end
end
end
return ""
end

def proc_double_dig(z)
if z==0
return ""
else
return @h[z]
end
end

def proc_single_dig(y)
if y==0
return ""
else
return @h[y]
end
end
protected :def_calc, roc_unit, roc_double_dig, roc_single_dig

end


puts 453645445.english_word

#FourtyFive Crore, Thirtysix Lakh, FourtyFive Thousand, Four Hundred,
FourtyFive


Regards,
P.Raveendran
--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
jazzez ravi
Guest
Posts: n/a
 
      04-06-2009
Hi vetri,

The above code works only upto billions.


Regards,
P.raveendran
http://raveendran.wordpress.com
--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
dictionary spanish-english/english spanish Ant1 Computer Support 2 12-15-2007 08:57 PM
I want to make English-speaking friend to practic my poor English IchBin Java 1 03-26-2006 05:36 AM
English/English DLL =?Utf-8?B?UmFlZCBTYXdhbGhh?= ASP .Net 2 10-16-2005 10:32 AM
Dictionaries for English-French and English-Spanish fkissam Computer Support 2 07-14-2004 09:07 PM
AMERICAN ENGLISH vs BRITISH, CANADIAN, or AUSTRALIAN ENGLISH Proud USA Babe Digital Photography 247 10-07-2003 12:32 AM



Advertisments