How do I turn the string "4.5" into the number 4.5 so I can do
arithmetic on it?
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
Thanks Rajinder, that did it!
···
On Dec 25, 10:51 am, Rajinder Yadav <devguy...@gmail.com> 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--
Kind Regards,
Rajinder YadavDo Good! - Share Freely
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"
···
On Fri, Dec 25, 2009 at 3:51 PM, Rajinder Yadav <devguy.ca@gmail.com> 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