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:

Was this post helpful?

Related Posts

  • 18 May

    How to Sum BigDecimal Using Stream in Java

    Table of ContentsSum BigDecimal in Java 5/6/7Sum BigDecimal in Java 8BigDecimal sum using ListBigDecimal Sum Using ArrayBigDecimal Sum Using MapStream Removes Null ValuesConclusionWas this post helpful? This article discusses how to sum BigDecimal using stream. One of the significant features in Java 8 is the introduction of stream functionality and a way of carrying out […]

  • 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

    Table of ContentsUsing BigDecimal constructorWas this post helpful? In this post, we will see how to convert

  • 19 December

    Java BigInteger to BigDecimal

    Table of ContentsUsing BigDecimal constructorWas this post helpful? 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-62e8358a05a3d242565323/] When you run above […]

  • 14 December

    BigDecimal divide

    Table of ContentsSyntaxReturn typeBigDecimal round exampleWas this post helpful? 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-62e8358a06119389906744/] […]

  • 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?Was […]

Leave a Reply

Your email address will not be published.

Subscribe to our newletter

Get quality tutorials to your inbox. Subscribe now.