From: Gavin Sinclair Date: 2002-12-11T07:37:44+09:00 Subject: Re: Proper Type for Dollar Amount From: "William Djaja Tjokroaminata" > Jim Weirich wrote: > > This is a consequence of representing numbers in floating point and is > > common whenever dealing with floating point numbers. Last week at work, > > I came across a situation where a sum of monetary amounts were off by a > > penny ... Yes, they were using floating point to represent dollar > > amounts. Never a good idea. > > Well, you can search comp.lang.c about a thread on what type to use > (int/long/double/etc.) to represent dollar amounts (including the > cents). I don't think there is a clear answer that representing dollar > amounts with floating point is a bad idea. It depends on what kinds of > operations you are going to do, which in this case is a division. > In the rare case that I have represented money, I've used an integer to represent the nuber of cents, with a "Currency" (or similar) class wrapped around it providing lots of groovy methods. Gavin