You should use the number_with_precision . See the document .
Example:
number_with_precision(1.5, :precision => 2) => 1.50
A helper is created inside you:
<%= f.text_field :cost, :class => 'cost', :value => (number_with_precision(f.object.cost, :precision => 2) || 0) %>
By the way, if you really want to display some price, use number_to_currency , the same page for doc (in the context of the form, I would save number_with_precision , you do not want to ruin the money symbols)
apneadiving Oct. 14 '11 at 19:59 2011-10-14 19:59
source share