my users can enter and create prices. I wanted to know how to do this when users enter 23.5 and instead get 23.50 or 0.0 get 0.00. How to add to t.decimal or my price: decimal the following abilities?
Thanks for the help!
Answer (: price with scale and accuracy)
class CreatePrices < ActiveRecord::Migration
def self.up
create_table :prices do |t|
t.string :price_name
t.decimal :price, :precision => 10, :scale => 2
t.date :date
t.timestamps
end
end
def self.down
drop_table :prices
end
end
schema.rb:
create_table "prices", :force => true do |t|
t.string "price_name"
t.decimal "price", :precision => 10, :scale => 2
t.date "date"
t.datetime "created_at"
t.datetime "updated_at"
t.integer "user_id"
end
my lining form: <% = f.label: price%>
<% = f.text_field: price%>
Then in your view, enter number_to_currency (@ model.attribute):
<B> Price:
source
share