Sanely Displaying Money Values
Posted on May 28, 2007 at 12:09 PM
If you need to display a a float/string formatted as money (with two decimal points), simply add a helper method to your application_helper.rb.
module ApplicationHelper
def two_dec(n)
sprintf("%.2f", n)
end
end
Now every time you need to display you value, just pass it into the two_dec method.
$<%= two_dec(@repair.cost) %>
Will produce: $150.00.
Comments
There are 0 comments on this post. Post yours →
Post a comment
Required fields in bold.