I write currency trading applications for living, so I have to work with monetary values (it\'s a shame that Java still doesn\'t have decimal float type and has nothing to s
I remember attending a sales presentation from IBM for a hardware accelerated implementation of BigDecimal. So if your target platform is IBM System z, or System p, you could exploit this seamlessly.
The following link might be of some use.
http://www-03.ibm.com/servers/enable/site/education/wp/181ee/181ee.pdf
Update: Link no longer works.
Only 10x performance increase desired for something that is 1000x slower than primitive?!.
Throwing a bit more hardware at this might be cheaper (considering the probability of having a currency calculation error).
What version of the JDK/JRE are you using?
Also you might try ArciMath BigDecimal to see if theirs speeds it up for you.
Edit:
I remember reading somewhere (I think it was Effective Java) that the BigDecmal class was changed from being JNI called to a C library to all Java at some point... and it got faster from that. So it could be that any arbitrary precision library you use is not going to get you the speed you need.
easy... round your results often will eliminate double data type's error. if you are doing balance calculation, you have to also consider who will own the more/less penny caused by rounding.
bigdeciaml calculation produces more/less penny too, consider 100/3 case.
Store longs as the number of cents. For example, BigDecimal money = new BigDecimal ("4.20")
becomes long money = 420
. You just have to remember to mod by 100 to get dollars and cents for output. If you need to track, say, tenths of a cent, it'd become long money = 4200
instead.
Maybe you should look into getting hardware accelerated decimal arithmetics?
http://speleotrove.com/decimal/