# Problem displaying correct price/decimal values

**URL:** <https://www.ruby-forum.com/t/problem-displaying-correct-price-decimal-values/146086>\
**Category:** Rails\
**Created:** [August 17, 2008, 7:17pm UTC](https://www.ruby-forum.com/t/problem-displaying-correct-price-decimal-values/146086 "2008-08-17T19:17:47Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![CPerry](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/9d8465/32.png) [@CPerry](https://www.ruby-forum.com/u/CPerry)\
**Post date:** [August 17, 2008, 7:17pm UTC](https://www.ruby-forum.com/t/problem-displaying-correct-price-decimal-values/146086/1 "2008-08-17T19:17:47Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![CPerry](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/9d8465/32.png) [@CPerry](https://www.ruby-forum.com/u/CPerry)\
**Post date:** [August 18, 2008, 3:15am UTC](https://www.ruby-forum.com/t/problem-displaying-correct-price-decimal-values/146086/2 "2008-08-18T03:15:28Z")

</div>

On Aug 17, 12:16 pm, CPerry [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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](http://www.purpleworkshops.com/workshops/rest-and-web-services)

---

<div class="post-metadata">

**Author:** ![CPerry](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/9d8465/32.png) [@CPerry](https://www.ruby-forum.com/u/CPerry)\
**Post date:** [August 18, 2008, 5:36am UTC](https://www.ruby-forum.com/t/problem-displaying-correct-price-decimal-values/146086/3 "2008-08-18T05:36:36Z")

</div>

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

–Cory
