0

Let's assume I have a string number such as 1000.0 and I want to create BigDecimal out of it in the following format: 1000.00

edit: And also if the string number already has a floating precision of two decimals, don't touch it.

How can I do this by using BigDecimals?.

KingMetin2
  • 69
  • 8
  • Formatting and precision are different things. In math, `1000.0` and `1000.00` are identical. You might wanna have a look at [this post](https://stackoverflow.com/q/2538787) instead. – Siguza Sep 18 '18 at 21:12

1 Answers1

2

Use setScale(...), something like that:

BigDecimal result = new BigDecimal("1000.0");
result.setScale(2, RoundingMode.HALF_UP);
Vladimir L.
  • 1,086
  • 10
  • 21