commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Bridges, Ed NYC" <EBrid...@citco.com>
Subject RE: Money Class?
Date Fri, 18 Mar 2005 18:20:34 GMT
Martin Fowler in his "Patterns of Enterprise Application Architecture" talks
about a money class and provides a sound implementation of same.
  http://www.martinfowler.com/ap2/quantity.html



-----Original Message-----
From: Dirk Verbeeck [mailto:dirk.verbeeck@pandora.be] 
Sent: Friday, March 18, 2005 2:14 AM
To: Jakarta Commons Users List
Subject: Re: Money Class?

Scale depends on the currency. For example Euro is displayed with 2 decimals
but internal calculations should be done with 4 decimals.

If you are doing a lot of divisions/multiplications then you better don't
limit the intermediate results or the rounding errors will kill the
correctness of the result.

I also recommend creating your own Money Class with a bigdecimal inside.
Then you can add method to read/write the value with the correct number of
decimal digits.

-- Dirk

Lukas Bradley wrote:
> 
>>    I always use BigDecimal for money, and convert to required formats 
>> when viewing. Otherwise, if you need to deal with other currencies, 
>> you might run into trouble.
> 
> 
> Do you limit (scale) your BigDecimal to 2 places?  If so, which 
> constructor do you use?
> 
> Thanks for the reply.


---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


Mime
View raw message