# How to represent price?

**URL:** <https://www.ruby-forum.com/t/how-to-represent-price/76298>\
**Category:** Rails\
**Created:** [November 17, 2006, 12:35pm UTC](https://www.ruby-forum.com/t/how-to-represent-price/76298 "2006-11-17T12:35:44Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Thushan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/8c91f0/32.png) [@Thushan](https://www.ruby-forum.com/u/Thushan)\
**Post date:** [November 17, 2006, 12:35pm UTC](https://www.ruby-forum.com/t/how-to-represent-price/76298/1 "2006-11-17T12:35:44Z")

</div>

As recomended by AWDWR (pg 85), is everyone using integer to store  
decimal values?  
Or is there a better way to do this?

Thanks in advance  
Thushan

---

<div class="post-metadata">

**Author:** ![Thushan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/8c91f0/32.png) [@Thushan](https://www.ruby-forum.com/u/Thushan)\
**Post date:** [November 17, 2006, 3:06pm UTC](https://www.ruby-forum.com/t/how-to-represent-price/76298/2 "2006-11-17T15:06:10Z")

</div>

Hi !

2006/11/17, Thushan [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> As recomended by AWDWR (pg 85), is everyone using integer to store  
> decimal values?  
> Or is there a better way to do this?

I use integer columns with a composed\_of :class\_name =\> ‘Money’

## Hope that helps !

FranÃ§ois Beausoleil  
[http://blog.teksol.info/](http://blog.teksol.info/)  
[http://piston.rubyforge.org/](http://piston.rubyforge.org/)

---

<div class="post-metadata">

**Author:** ![Thushan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/8c91f0/32.png) [@Thushan](https://www.ruby-forum.com/u/Thushan)\
**Post date:** [November 17, 2006, 4:18pm UTC](https://www.ruby-forum.com/t/how-to-represent-price/76298/3 "2006-11-17T16:18:25Z")

</div>

On Nov 17, 2006, at 4:34 AM, Thushan wrote:

> As recomended by AWDWR (pg 85), is everyone using integer to store  
> decimal values?  
> Or is there a better way to do this?

The new edition recommends using decimal columns once Rails 1.2 comes  
out.

Cheers

Dave

---

<div class="post-metadata">

**Author:** ![Thushan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/8c91f0/32.png) [@Thushan](https://www.ruby-forum.com/u/Thushan)\
**Post date:** [November 17, 2006, 9:48pm UTC](https://www.ruby-forum.com/t/how-to-represent-price/76298/4 "2006-11-17T21:48:35Z")

</div>

Michael K. wrote:

> Out of curiosity what does rails 1.2 have to do with the use of  
> decimal columns?

Check out:  
[http://blogs.pragprog.com/cgi-bin/pragdave.cgi/Tech/Random/Rounding.rdoc](http://blogs.pragprog.com/cgi-bin/pragdave.cgi/Tech/Random/Rounding.rdoc)

I believe that versions of Rails before 1.2, convert database decimal  
amounts to floats in Ruby. If you check out the link above, you can see  
that unfortunately that doesn’t provide the precision that’s desired for  
cash-related applications.

A patch was submitted:  
[http://dev.rubyonrails.org/ticket/5454](http://dev.rubyonrails.org/ticket/5454)  
that fixes this and provides support for high-precision decimal columns  
to BigDecimal Ruby objects.

The patch will be a part of the core in Rails 1.2.

---

<div class="post-metadata">

**Author:** ![Thushan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/8c91f0/32.png) [@Thushan](https://www.ruby-forum.com/u/Thushan)\
**Post date:** [November 17, 2006, 8:03pm UTC](https://www.ruby-forum.com/t/how-to-represent-price/76298/5 "2006-11-17T20:03:13Z")

</div>

Out of curiosity what does rails 1.2 have to do with the use of  
decimal columns? I’ve been using  
decimal columns for my currency needs on my site for over a year  
without any issues (that I know of).  
I’ve done testing to ensure my math is correct and haven’t seen any  
problems.  
I’m afraid of what problems I’m missing by not understanding the  
issue at large. I’m using rails 1.1.6.

-Michael  
[http://javathehutt.blogspot.com](http://javathehutt.blogspot.com)
