KingMetin2
KingMetin2

Reputation: 99

How to increase the floating point precision of a number by using BigDecimals in java?

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?.

Upvotes: 0

Views: 79

Answers (1)

Vladimir L.
Vladimir L.

Reputation: 1126

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

BigDecimal result = new BigDecimal("1000.0");
result.setScale(2, RoundingMode.HALF_UP);

Upvotes: 2

Related Questions