Created
December 8, 2011 17:09
-
-
Save firebelly/1447646 to your computer and use it in GitHub Desktop.
simple dollars to decimal conversions in Ruby
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 format_as_dollars(c) | |
unless c.nil? | |
c = (c * 100).round / 100 | |
"$%.2f" % c | |
end | |
end | |
def decimal_from_currency(c) | |
if c =~ /\$/ | |
c = c[1, c.length] | |
end | |
BigDecimal(c.to_s) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment