Reputation: 9573
My Rails app allows users to add the price of their item; it's in the model. However, for example if I say I want to sell something for $25, Rails renders it as $25.0. That just isn't standard -- it should be $25.00. Or if the user prices something at $120, it should display as $120.00. Here's the migration that I originally did:
class AddDecimalPriceToProducts < ActiveRecord::Migration
def change
add_column :products, :decimal_price, :decimal, :precision => 8, :scale => 2
end
end
Should I change the scale or precision to do what I'd like?
Upvotes: 0
Views: 106
Reputation: 2946
no, decimal is fine - instead, what you want to do in the frontend is use the helper number_to_currency(@product.decimal_price, precision: 2)
Upvotes: 1