Last active
August 29, 2015 13:56
-
-
Save kitwalker12/9085896 to your computer and use it in GitHub Desktop.
check if string is float and/or whole number
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def is_number?(str) | |
true if Float(str) rescue false | |
end | |
def prettify(str) | |
str = str.to_f | |
str.to_i == str ? str.to_i : str | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment