From: Robert Klemme Date: 2012-01-31T02:07:46+09:00 Subject: Re: Microrant on Ruy's Math Skills On Mon, Jan 30, 2012 at 5:52 PM, Tony Arcieri wrote: > On Mon, Jan 30, 2012 at 1:01 AM, Florian Gilcher wrote: > >> On Jan 30, 2012, at 9:32 AM, Tony Arcieri wrote: >> > I have found many uses for BigDecimal before and have seen Fixnums used >> > where BigDecimal would probably be more appropriate (i.e. "count cents, >> not >> > dollars!") where having (Big)Decimal literals would probably change >> > people's minds about that sort of thing. >> >> Counting cents is perfectly valid, fits every database (even your fancy >> NOSQL >> database that doesn't have a decimal type) and is the proper way to do math >> involving money. The base value is not the Dollar, it is the >> cent. > > Having worked on these sorts of systems, I really hate them. Having to > constantly multiply and divide by 100 because, sorry, in the real world > it's dollars, not cents, that people actually work with and familiar with, > you leave yourself open for all sorts of off by two orders of magnitude > errors doing these sorts of conversions all over the place. Well, you only convert during reading from and writing to the database. The rest of the software works with instances of a proper class which handles all the nifty details internally. That's the whole point of OO, isn't it? Cheers robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/