The core java math class also provides implementations that properly rounds, truncates, performs ceiling, and similar. For instance, one of the round methods are:
static long round(double a) -- Returns the closest long to the argument, with ties rounding to positive infinity.
https://docs.oracle.com/en/java/javase/ ... /Math.html
Truncating Doubles
Re: Truncating Doubles
If you want direct control over the precision of floating point (double) calculations, you can use BigDecimal.
It's a bit awkward (and slower), but means there's less chance of results with unexpected rounding errors.
https://medium.com/@reachansari/use-of- ... 1440bdd5f4
VM has 'cents' too
Cheers,
--
Terry McG
It's a bit awkward (and slower), but means there's less chance of results with unexpected rounding errors.
https://medium.com/@reachansari/use-of- ... 1440bdd5f4
VM has 'cents' too
Cheers,
--
Terry McG