Newbie Question

C

Colin Bartlett

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"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,813
Messages
2,569,696
Members
45,480
Latest member
CrazyMember

Latest Threads

Top