How to represent price?

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

Hi !

2006/11/17, Thushan [email protected]:

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://piston.rubyforge.org/

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

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

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

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