Skip to content

Instantly share code, notes, and snippets.

@TheNicholasNick
Created August 4, 2009 08:27
Show Gist options
  • Save TheNicholasNick/161106 to your computer and use it in GitHub Desktop.
Save TheNicholasNick/161106 to your computer and use it in GitHub Desktop.
BigDecimal to Money (without the symbol)
# all my bigdeciamls going into this have been .round(2) beforehand
dollar[1] = dollar[1].split[1]
dollar[1] = "#{dollar[1][0, dollar[1].length-2].gsub(/(\d)(?=(\d\d\d)+(?!\d))/, "\\1,")}.#{dollar[1][dollar[1].length-2,2]}"
# credit where credit is due, I stole the gsub part from merb numeric helper - thanks merb!!
# the rest was bigdecimal docs :)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment