Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Determine If A String Is Numeric In Ruby

DZone's Guide to

Determine If A String Is Numeric In Ruby

· ·
Free Resource
# Determine if a string is numeric using Float and rescue
# Revised short version from http://rosettacode.org/wiki/Determine_if_a_string_is_numeric#Ruby


def numeric?(s)
    Float(s) != nil rescue false
end
Topics:

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}