Problem displaying correct price/decimal values

Hey all, I am working on an app where people can post items for sale.
When they post an item, they add a price to that item.

When the item gets output to the page, it will not display the second
number AFTER the decimal if it is a 0. If it is any other number, it
displays fine. So, prices display as $25.0 if it ends in 0, but $25.95
if it ends in any other number.

Here is the code in my migration to create that column in the database

t.column :price, :decimal, :precision => 8, :scale => 2, :default =>
0, :null => false

I was pretty sure that the :scale => 2 meant two numbers would be
after the decimal, which seems to work fine.

I am then outputting my price in my view with this code........ <p>$<
%= item.price %></p>. Also, in my form that I have to add a new
listing, the input field for the price is being pre-populated with
0.0. I would like to remove that as well.

Can anyone shed some light on this for me, as I appear to be missing
something simple!



Try number_to_currency() in your views whenever you want to display
the amount. You can specify how many digits after the decimal point
to show (default is 2).


REST with Rails
Oct 4, 2008, Austin, TX

Thanks Jeff, I had already figured it out using the exact helper that
you mentioned!