From: Rick DeNatale Date: 2010-07-12T02:05:15+09:00 Subject: Re: Basic Question: How do you check to see if gets is a number? On Sun, Jul 11, 2010 at 12:34 PM, Adam Bourg wrote: > if ( age.to_f.to_s == true ) This will NEVER happen. age.to_f converts the string to a float. If the string isn't valid it returns 0.0. age.to_f.to_s will ALWAYS be a string, and will never == true >  monthsold = age.to_i * months.to_i >  puts 'You are ' + monthsold.to_s + ' months old' > else > Now I'm not sure whether or not you really want to accept an age as a float, or just an integer, but you need to do something else to validate the string. One way would be to use a regular expression, e.g. something like if age =~ /^d+$/ # for an integer or if age =~/^d+(|\.\d*)$/ # for a float These are fairly strict in what they'll accept, you might want slightly different regular expressions, particularly if you really want a float. Or use either Kernel#Integer or Kernel#Float which raise an error if they don't like the string: float_age = Float(age) rescue nil if float_age #.... HTH -- Rick DeNatale Blog: http://talklikeaduck.denhaven2.com/ Github: http://github.com/rubyredrick Twitter: @RickDeNatale WWR: http://www.workingwithrails.com/person/9021-rick-denatale LinkedIn: http://www.linkedin.com/in/rickdenatale