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…

$<
%= item.price %>

. 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!

Thanks!

–Cory

On Aug 17, 12:16 pm, CPerry [email protected] wrote:

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.

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).

Jeff

REST with Rails
Oct 4, 2008, Austin, TX
http://www.purpleworkshops.com/workshops/rest-and-web-services

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

–Cory