0

Does anyone know of a good money library that's optimized for doing math?

Joda money seems optimized for doing things like displaying currencies and so forth. I'm looking for one that is designed for things like:

  • Average price
  • Iterating through prices (e.g. $1.00, $1.10, $1.20)
  • Dividing by a currency (e.g. units per dollar)

And other similar things.

Motivation: Avoid double rounding problems without having the performance hit of BigDecimal.

  • 1
    I personally use integer and cents for this and only switch to euro/dollar in display (by dividing through 100). That way I can use the regular math stuff. That will make the numbers consistent (thus avoiding double rounding problems) but has some tricky problems itself. – Angelo Fuchs Oct 8 '14 at 8:09
  • 1
    @AngeloNeuschitzer - just be careful with that approach to make sure you are using a small enough base unit for your target market. For some situations (selling gasoline, for instance) prices are in fractions of a cent, so you need to use dollar/1000 instead of 100. – Michael Kohne Oct 8 '14 at 13:06
  • @MichaelKohne Yes. Very important indeed. One needs to use the correct precision. – Angelo Fuchs Oct 8 '14 at 14:15
-1

One possible option. Uses an Amount class that you can type as money. Amount<Money> tripCost;

Note that I do not work very much in Java lately, and have not used this library myself.

http://www.jscience.org/api/org/jscience/economics/money/package-summary.html#package_description

  • Out of curiosity, is this not a good option to do money calculations? Or did my comment about not having used it necessitate the down-vote? If it is the former, some insights about the packages shortcomings would be helpful for posterity. – Matthew Vines Oct 8 '14 at 20:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.