Created
June 19, 2013 19:03
-
-
Save mattmawhinney/5816991 to your computer and use it in GitHub Desktop.
A method to insert commas into numbers that are 4 digits or longer. An exercise in using regular expressions.
This file contains 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 separate_comma(number) | |
number.to_s.gsub(/(\d)(?=(\d{3})+$)/, '\1,') | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment