From: Robert Klemme Date: 2012-07-12T22:10:22+09:00 Subject: Re: how to check string is numeric or not On Thu, Jul 12, 2012 at 12:16 PM, Lucky Nl wrote: > I want to check the value is numeric or not According to your example you want to check whether a string represents an integer value (floats are numeric, too). > For example > when i am checking numeric or not am expecting as below results > "34" => true > 34 => true > "34sdfds" => it should return false > 34.90 => false You can use Integer() to do that: Ruby version 1.8.7 irb(main):001:0> %w{34 34sdfds 34.90}.each do |s| printf "%p: %p\n", s, (Integer(s) rescue false) end "34": 34 "34sdfds": false "34.90": false => ["34", "34sdfds", "34.90"] But actually you do not need a separate check, just use Integer to convert the string to a Fixnum / Bignum and deal with the exception. Kind regards robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/