Created
August 28, 2012 19:06
-
-
Save lenagroeger/3502562 to your computer and use it in GitHub Desktop.
helper to turn $5,758,937 into $5M
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 fmt_stat(stat, prefix = "$") | |
stat = case stat | |
when -999999999999..-10000 then number_to_human(stat, :units => {:million => "M", :thousand => "K", :billion => "B"}).gsub(/ /,'') | |
when -9999..9999 then number_with_delimiter(stat) | |
when 10000..999999999999 then number_to_human(stat, :units => {:million => "M", :thousand => "K", :billion => "B"}).gsub(/ /,'') | |
when nil then number_with_delimiter(0) | |
else stat | |
end | |
stat = stat === "N/A" ? stat : "#{prefix}#{stat}" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment