Bruno Miranda's Notebook

Personal Blog about Ruby on Rails, XHTML, CSS, and Design

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.