From: Colin Bartlett Date: 2009-12-26T02:03:54+09:00 Subject: Re: Newbie Question On Fri, Dec 25, 2009 at 3:51 PM, Rajinder Yadav wrote: > lalawawa wrote: >> >> How do I turn the string "4.5" into the number 4.5 so I can do >> arithmetic on it? > > irb(main):017:0> "4.5".to_f > => 4.5 Or if you want "4.5" to convert to a Float but "4.5q" to raise an error/exception: Float("4.5") #=> 4.5 Float("4.5q") #=> ArgumentError "invalid value for Float"