Alex Rivera | Logout

Rails 3. How to display two decimal places in edit form?

Asked 2011-10-14T19:53:31.507
72

I have this edit form.

But when I store something such as 1.5, I would like to display it as 1.50.

How could I do that with the form helper? <%= f.text_field :cost, :class => 'cost' %>

Edit
Report

1 Answer

47

Alternatively, you can use the format string "%.2f" % 1.5. http://ruby-doc.com/docs/ProgrammingRuby/#Kernel.sprintf

answered 2011-10-14T20:02:01.620

Your Answer