We have a highly complex financial model app that involves money & percentages. It's written in C# and we use its decimal
type to represent both. It works fine, but we're trying to migrate the app to Java to get away from Microsoft.
I'm surprised to not find any Java native type to store money & percentages that provides both:
- Lossless precision
- Native style of doing calculations (e.g. using
+
for additions instead of.add()
)
I know the consensus is to use BigDecimal. That solves the storage part but it's very cumbersome to do calculations with it. For example instead of this with decimal
:
((a + b + c + d) / e) * f
I'd have to do this with BigDecimal
:
a.add(b).add(c).add(d).divide(e).multiply(f)
This is fine for a small amount of calculations, but we have thousands of calculations, some of their formulae are tens of lines. This quickly becomes unwieldy and hard to read.
Basically I'm looking for the exact replica of C#'s decimal
type in Java.