howdy I'm in the progress of modeling a system for a financial company and I was wondering wether I should use BigDecimal or double for financial data. From what I've read by now you can't really trust double to store financial numbers but BigDecimal has some downsided too: - it's slow (MUCH slower) - can't use normal operators on them; have to resort to method calls - only basic operations on BigDecimals are available
Originally posted by Thomas Paul: Why not just use ints? Multiply all your numbers by 100 so that you carry cents. Then just worry about converting them to a decimal format when you need to store or display them.
Well, afaik most financial applications need to work on the thousandth part of a cent or something, but you should be able to use int or long as long as you don't need *arbitrary* precision. (Don't forget to encapsulate it in its own Money class!)
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Dave Van Even
Joined: Jul 19, 2001
thanks so far everybody I'm not so keen on implementing my own 'Money' class The thing is I'm using these things with EJB and I'm wondering wether it'll all work... Perhaps the BigDecimal isn't so bad after all. I know that works for shure... Pitty java doesn't have operator overloading I remember stuff back from the C++ days, it can really help you out in some situations. I do understand SUNs decision not to implement operator overloading though..
Joined: Dec 10, 2001
What do you think could be accomplished with operator overloading that cannot be otherwise accomplished?