Newbie Question

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


Kind Regards,
Rajinder Y.

http://DevMentor.org

Do Good! - Share Freely

On Dec 25, 10:51 am, Rajinder Y. [email protected] wrote:

http://DevMentor.org

Do Good! - Share Freely

Thanks Rajinder, that did it!

On Fri, Dec 25, 2009 at 3:51 PM, Rajinder Y. [email protected]
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”