Skip to content

Instantly share code, notes, and snippets.

@firebelly
Created December 8, 2011 17:09
Show Gist options
  • Save firebelly/1447646 to your computer and use it in GitHub Desktop.
Save firebelly/1447646 to your computer and use it in GitHub Desktop.
simple dollars to decimal conversions in Ruby
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