Java – How to round a BigDecimal value in Java ?

Published on March 9, 2016 by abundantcode

Filed under Java

Last modified March 9, 2016

Print this page

rate 1 star rate 2 star rate 3 star rate 4 star rate 5 star
Your rating: none, Average: 0 (0 votes)

This article have been viewed 1897 times

Problem Statement

You need round the BigDecimal value in your Java program.


Use the setScale method that is defined in the BigDecimal to round the value of the BigDecimal. You can also set the parameters like BigDecimal.ROUND_HALF_UP etc to the method.

import java.math.BigDecimal;

public class Main {

    public static void main(String[] args) {

        System.out.println(" Java Tutorials");

        BigDecimal input1 = new BigDecimal(10102.15679);
        BigDecimal output = input1.setScale(2,BigDecimal.ROUND_HALF_UP);


Output of the above program is Java Tutorials


If you enjoyed this post, please consider leaving a comment or subscribing to the RSS feed to have future articles delivered to your feed reader.

Leave a Comment


You might be Interested in these Posts

How to use array Rank in C# ?

In C# , the Rank property of the array is is used to get the rank of the array. In simple terms , ra...

How to append an array to another in JavaScript ?

In JavaScript , you may want to append one array to another array(s) to combine their elements resul...

Building a ASP.NET Web API in Visual Studio 2015

This blog post will explain on how to create a Simple ASP.NET Web API using Microsoft Visual Studio ...