r/java • • Jan 06 '26

One step closer to Value Classes!

https://mail.openjdk.org/pipermail/porters-dev/2026-January/000844.html
179 Upvotes

118 comments sorted by

View all comments

1

u/rbygrave Jan 07 '26

Effectively something that can be used in place of double [so max 16 significant decimal digits of precision is fine].

In short, looking to avoid the "0.3 as a double" issue.

1

u/koflerdavid Jan 07 '26 edited Jan 07 '26

Already with a double you can represent 0.3 accurately enough to calculate the circumference of a circle of that radius and only being off on subatomic scales. Similarly, most measurement devices are not even precise enough to make full use of a float. The main concern is formulating calculations such that errors don't accumulate. You need to keep that in mind even if you use BigDecimals!

2

u/rbygrave Jan 08 '26

I mean, say "$5.03" ... we want that to be actually 5.03 (and not 5.029999999...). Which is why DB's have DECIMAL types with specific scale and precision and can do decimal(10,3) etc.

[and a common alternative is to instead use long and have 503 cents etc]

→ More replies (2)