r/java • • Jul 23 '26 • Bravo 1

JEP 540: Simple JSON API (Incubator)

https://openjdk.org/jeps/540
79 Upvotes

81 comments sorted by

View all comments

Show parent comment

3

u/agentoutlier Jul 23 '26

  Same. Most financial applications use fixed precision decimals. BigDecimal is their natural representation in java; the other existing java types (double, long, etc) do not model them well.

From my experience other than UI most use long or multiple longs. At least fintech does.

However I don’t have experience with traditional banking and most of my experience is simple billing.

I vaguely remember reading comment that u/rzwitserloot had similar experience and fair bit more on financial coding experience than myself and indicated folks use longs.

1

u/gnahraf Jul 24 '26

You're right. The common workaround is to express such fixed precision data in their smallest unit, for eg, in cents instead of dollars. For other units, it's not so clear (eg units of weight).

You can also model fixed decimals using a long (unscaled value) and a byte (for where the decimal point goes). Like a lightweight, but fixed-range, BD. But, ofc, this would be clumsy in json.

3

u/ThinkPreparation8975 Jul 24 '26

Don't forget about unitless numbers, of which there are plenty - rate, percent, factor, even ratio (how do you express 1/3?).

And why would you suffer with modeling decimals with a long and a byte yourself, when the Java library has already solved this problem for you?

BigDecimals are ubiquitous in most financial circles. I don't know about HFT, but for banks' middle- and backoffice they are the obvious choice.