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.


You may also like:

Related Posts

  • Java BigDecimal to Double
    17 May

    Java BigDecimal to Double

    Learn about how to convert BigDecimal to Double in java

  • 22 December

    Java BigDecimal to BigInteger

    In this post, we will see how to convert

  • 19 December

    Java BigInteger to BigDecimal

    In this post, we will see how to convert BigInteger toBigDecimal in java. Using BigDecimal constructor You can simply use BigDecimal’s following constructor to convert BigInteger to BigDecimal. BigDecimal(BigInteger val) Here is the complete example to convert BigInteger to BigDecimal in java. [crayon-60fc21996205f254169728/] When you run above program, you will get below output: BigDecimal bd: […]

  • 14 December

    BigDecimal divide

    Table of ContentsSyntaxReturn typeBigDecimal round example In this tutorial we will see about BigDecimal‘s divide method. BigDecimal’s divide method is used to divide one BigDecimal by another. You can specify scale and rounding mode to get the output according to your need. There are 6 overloaded versions of divide method. Syntax [crayon-60fc21996292b331154398/] Return type returns […]

  • 12 October

    Java BigDecimal

    Table of ContentsConstructorsMethodsFAQsHow can you compare two BigDecimals?How to set scale in case of BigDecimalsHow to convert String to BigDecimal?How to convert BigDecimal to String?How to add two BigDecimals in java?How to subtract two BigDecimals in java?How to multiply two BigDecimals in java?How to divide two BigDecimals in java?How to remove trailing zero from BigDecimal? […]

  • 05 October

    Java BigDecimal to String

    Table of ContentstoString methodString’s ValueOf methodIssues with toString In this post, we will see how to convert BigDecimal to String in java. There are many ways to convert BigDecimal to String in java. Some of them are: Using toString() Using String.valueOf() toString method You can simply use BigDecimal’s toString method to convert BigDecimal to String. […]

Leave a Reply

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

Subscribe to our newletter

Get quality tutorials to your inbox. Subscribe now.