Created
September 4, 2014 07:56
-
-
Save ipmsteven/1ee106da07e1821cedbe to your computer and use it in GitHub Desktop.
simple rails number_to_currency
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 format_currency(number) | |
| return number if number.blank? | |
| parts = ("%.2f" % number).split('.') | |
| parts[0].gsub!(/(\d)(?=(\d\d\d)+(?!\d))/, "\\1,") | |
| parts.join('.') | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment