Reputation: 99
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
Reputation: 1126
Use setScale(...), something like that:
BigDecimal result = new BigDecimal("1000.0");
result.setScale(2, RoundingMode.HALF_UP);
Upvotes: 2