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?
Asked
Active
Viewed 86 times
0
-
3You 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
-
1You 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 Answers
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
-
-
Did you assign a value to this placeholder's example `myBigDecimal`? Can you copy details of NumberFormatException here (no screenshot, please)? – Christoph Dahlen Nov 22 '22 at 08:13