0

I have bigDeciaml format and digits like 14.2345 or 2.567 or 6.65346. How to format bigDeciaml to leave 3 characters after dot?

  • 3
    You can't. believe it or not, but a BigDecimal is NOT a String. You should be looking at "rounding" your numbers, not substring – Stultuske Nov 22 '22 at 07:13
  • 1
    You might want to look at `DecimalFormat` and the JavaDoc on the class. This let's you define a number format which includes rounding/truncation and let's you _format_ a `BigDecimal` to `String`. – Thomas Nov 22 '22 at 07:18

1 Answers1

0

I think you want a formatted display of BigDecimal, which includes conversion to String.

You may use

var formatted = String.format("%.3f", myBigDecimal);
Christoph Dahlen
  • 826
  • 3
  • 15