BigDecimal round

In this tutorial, we will see about BigDecimal‘s round method. BigDecimal’s round method is used to round the BigDecimal based on MathContext setting.

Syntax

Return type

returns BigDecimal rounded with MathContext setting

BigDecimal round example

Let’s understand BigDecimal method with the help of example

Above program will generate below output.

80.23776 is rounded to: 80.24
80.23776 is rounded to: 80.23 with help of RoundingMode

BigDecimal setScale method

You can use setScale method also to round BigDecimal.Let’s understand with the help of example.

When you run above program, you will get below output.

BigDecimal Rounding to 3 decimal places: 12.457

That’s all about BigDecimal round method.


Was this post helpful?

Leave a Reply

Your email address will not be published. Required fields are marked *