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

前端 未结 4 2006

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.

4条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-04 13:34

    For this I use the number_to_currency formater. Since I am in the US the defaults work fine for me.

    <% price = 45.9999 %>
    <%= number_to_currency(price)%>
    => $45.99
    

    You can also pass in options if the defaults don't work for you. Documentation on available options at api.rubyonrails.org

提交回复
热议问题