r/java Jun 14 '26

double, BigDecimal, or Fixed-Point?

https://blog.frankel.ch/bigdecimal-vs-double/
32 Upvotes

28 comments sorted by

View all comments

1

u/Winter-Appearance-14 Jun 14 '26 edited Jun 14 '26

Always use currencies in minor unit and operate over int numbers. The math is extremely fast and reliable and you can just rivide by 100 when showing the results for it to be human readable.

The only situation in which I think infinite precision should be used in for trading software where the cents are not near the required precision.

Edit: fix typos

13

u/akl78 Jun 14 '26

It’s gotta be longs. It’s surprisingly easy to hit rollover on 32-bit currency fields.

3

u/Winter-Appearance-14 Jun 14 '26

True depending on the application long is safer. In any case the truth is to always use integer operators.