From: Andrei Maxim Date: 2007-11-24T22:21:46+09:00 Subject: Re: Convert words to numbers and back? ------=_Part_46347_10240809.1195910509581 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Content-Disposition: inline I think the OP wants to know how he could turn 3 into "three" or 2001 into "two thousand and one". On 11/24/07, saladin.mundi@gmx.de wrote: > > I don't know exactly what you mean. > Do you have something like: "123" <- a String which you want to conert > into > an integer? like 123 ? > > if so, there are these functions: > > str.to_i(base=10) => integer > > Returns the result of interpreting leading characters in str as an integer > base base (2, 8, 10, or 16). Extraneous characters past the end of a valid > number are ignored. If there is not a valid number at the start of str, 0 > is > returned. This method never raises an exception. > > "12345".to_i #=> 12345 > "99 red balloons".to_i #=> 99 > "0a".to_i #=> 0 > "0a".to_i(16) #=> 10 > "hello".to_i #=> 0 > "1100101".to_i(2) #=> 101 > "1100101".to_i(8) #=> 294977 > "1100101".to_i(10) #=> 1100101 > "1100101".to_i(16) #=> 17826049 > orstr.to_f => floatReturns the result of interpreting leading characters > in > str as a floating point number. Extraneous characters past the end of a > valid number are ignored. If there is not a valid number at the start of > str, 0.0 is returned. This method never raises an exception. > "123.45e1".to_f #=> 1234.5 > "45.67 degrees".to_f #=> 45.67 > "thx1138".to_f #=> 0.0 > bye sala----- Original Message ----- > From: "Andrei Maxim" > To: "ruby-talk ML" > Sent: Saturday, November 24, 2007 2:05 PM > Subject: Re: Convert words to numbers and back? > > > > Check http://www.deveiate.org/projects/Linguistics/ > > I think numwords is what you are looking for. > > > > On 11/24/07, Jordon Bedwell wrote: > >> > >> I was wondering if somebody could give me some insight and help on how > >> to convert words to numbers and back again. Maybe a function? > >> -- > >> Posted via http://www.ruby-forum.com/. > >> > >> > > -- > > Andrei Maxim > > http://andreimaxim.ro > > > > > -- Andrei Maxim http://andreimaxim.ro ------=_Part_46347_10240809.1195910509581--