0

I'm trying to use BigDecimals to calculate something and then round to 5 decimal places if it has more than that. How can I do this?

Would scale() work?

1 Answers1

0

Did you already crawl through JavaDoc, especially the function precision()?

And this here might be a direct solution which makes it needless to check the precision first:

yournumber.round(new MathContext(5, HALF_UP));

And after that use stripTrailingZeros() (thx to @GregKopff)

Daniel Alder
  • 5,031
  • 2
  • 45
  • 55