I am hitting a floating-precision problem : one of my results of dividing between Doubles
and/or Long
gives me 2.8421709430404007E-14
instead of 0
.
So I guess I have to use BigDecimals
(bigdec
more precisely).
My question is :
bigdec
convert all other numbers involved in the operation to a suitable type ?*'
, but /'
doesn't seem to exist.If you use any doubles (or floats) in your computation, the final result will be a double.
Otherwise any computation involving BigDecimal
s will return a BigDecimal
result or throw an exception.
Exceptions might be thrown if the result cannot be represented exactly, if some intermediate computation causes long overflow, or if you divide by zero.
+'
etc. promote to BigInteger
where +
would cause integer overflow.
Rounding can be introduced to deal with exact representation issues – see (doc with-precision)
.