There is no way to get BigDecimal
precision on a double
. double
s have double precision.
If you want to guarantee precise results use BigDecimal
.
You could create your own variant using a long
to store the integer part and an int
to store the fractional part - but why reinvent the wheel.
Any time use double
s you stand to stuffer from double precision issues. If you use them in a single place you might as well use them everywhere.
Even if you only use them to represent data from the database then will round the data to double precision and you will lose information.