On 12/16/05, James Edward G. II [email protected] wrote:
On Dec 16, 2005, at 4:39 PM, Stephen W. wrote:
Excuse my ignorance, but I’m wondering what BigDecimal does
different than the built-in integer types?It doesn’t use floating point arithmetic. That means it is accurate,
but slower.
And built-in integer types represent integers, not decimals.
That does however, bring up the point of using an integer
representation instead of floating point, eg. manipulating integer
pennies instead of decimal dollars. If you are certain that integer
arithmetic – with it’s corresponding truncation; eg. (5 / 3) * 3
returns 3, not 5 – is sufficient for your application, it can be
faster than BigDecimal. AFAIK, BigDecimal is doing this same thing
(integer representation), behind the scenes, but is slower due to the
requirements of being flexible in how many decimal places it
represents.
Another class to look into along these lines – slower but more
encapsulated than a “roll your own” integer representation, and more
domain specific than BigDecimal – is the great Money library from
Tobias
Lütke:
http://dist.leetsoft.com/api/money/
Jacob F.