Well this one works...

double roundOff = Math.round(a * 100.0) / 100.0;

Output is

123.14

Or as @Rufein said

 double roundOff = (double) Math.round(a * 100) / 100;

this will do it for you as well.

Answer from Bharat Sinha on Stack Overflow
Discussions

How do I round of to a specific decimal point?
If you just need to print rounded, try format method: System.out.format("%.2f%n",result); More on reddit.com
🌐 r/java
6
0
February 16, 2014
how do i round a double to 2 decimal places
hi, i want to round the result of a calculation (that is returned as a double) to 2 decimal places. which Math method do I use? More on forums.oracle.com
🌐 forums.oracle.com
December 17, 2003
How to round a number to n decimal places in Java? - TestMu AI Community
How can I round a number to n decimal places in Java? I need a method to round a double in Java using the half-up rounding method, meaning if the digit to be rounded is 5, it always rounds up. Additionally, I want to ensure that only significant digits are displayed—there should be no trailing ... More on community.testmuai.com
🌐 community.testmuai.com
0
February 3, 2025
Truncate to 2 decimal places in Java
The most obvious solution is to multiply by 100, cast to int and multiply by 0.01 but I'm not sure if this could lead to small rounding errors (something I normally don't want to rule out when doing arithmetic with floating point numbers). More on reddit.com
🌐 r/learnprogramming
6
1
December 22, 2021
🌐
GeeksforGeeks
geeksforgeeks.org › java › java-program-to-round-a-number-to-n-decimal-places
Java Program to Round a Number to n Decimal Places - GeeksforGeeks
January 22, 2026 - In this approach, we first Multiply the number by 10n using the pow() function of the Math class. Then the number is rounded to the nearest integer. At last, we divide the number by 10n.
🌐
Sentry
sentry.io › sentry answers › java › round a number to n decimal places in java
Round a Number to N Decimal Places in Java | Sentry
January 15, 2025 - The result is a string with the value rounded to 2 decimal places. ... The String.format() method is easy and useful when you need to display formatted numbers, but like DecimalFormat, the result is a string and not suitable for further numerical calculations. To make the rounding process reusable, you can create a custom utility method that encapsulates one of the approaches shown above. ... import java.math.BigDecimal; import java.math.RoundingMode; public class Main { public static void main(String[] args) { double value = 12.34567; double roundedValue = roundToNDecimalPlaces(value, 2); System.out.println("Rounded value: " + roundedValue); } public static double roundToNDecimalPlaces(double value, int decimalPlaces) { BigDecimal bd = new BigDecimal(Double.toString(value)); bd = bd.setScale(decimalPlaces, RoundingMode.HALF_UP); return bd.doubleValue(); } }
🌐
Baeldung
baeldung.com › home › java › java numbers › how to round a number to n decimal places in java
How to Round a Number to N Decimal Places in Java | Baeldung
September 24, 2025 - In this quick tutorial, we’ll ... decimal places in Java. Java provides two primitive types that we can use for storing decimal numbers: float and double. Double is the default type: ... However, we should never use either type for precise values like currencies. For that, and also for rounding, we can use the BigDecimal class. Let’s start with the core—Math.round()—this ...
🌐
Coderanch
coderanch.com › t › 776097 › java › Rounding-decimals
Rounding decimals (Java in General forum at Coderanch)
August 17, 2023 - Using Sam's example of 87.3923 rounded to the nearest thousandth, that would be 1. 87.3923 * 1000 = 87392.3 2. 87392.3 + 0.5 = 87392.8 3. Truncated = 87392.0 4. 87392.0 / 1000 = 87.392 There are several possible gotcha's here for negative numbers and some special values of double. It's simpler to use Math.round() which handles those for you.
Find elsewhere
🌐
Reddit
reddit.com › r/java › how do i round of to a specific decimal point?
r/java on Reddit: How do I round of to a specific decimal point?
February 16, 2014 -

For example, this:

 	public static void main(String[] args) {

	double x = 5.56;
	double y = 7.863;
	double result = x * y;
	System.out.println(result);
}

 }

prints a result of '43.71828'. How would I round the output off to '43.72'?

🌐
Qlik Community
community.qlik.com › t5 › Talend-Studio › resolved-How-to-make-float-round-to-2-decimal-places-in-tMap › td-p › 2350563
[resolved] How to make float round to 2 decimal places in tMap?
August 23, 2023 - Try this one..... round a number to 2 decimal places Mercal ... Ditto - same here! ... If they are floats, you don't need to turn them into bigdecimals. You could easily use Math.round().
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Math › round
Math.round() - JavaScript | MDN
console.log(Math.round(0.9)); // Expected output: 1 console.log(Math.round(5.95), Math.round(5.5), Math.round(5.05)); // Expected output: 6 6 5 console.log(Math.round(-5.05), Math.round(-5.5), Math.round(-5.95)); // Expected output: -5 -5 -6
🌐
TheServerSide
theserverside.com › blog › Coffee-Talk-Java-News-Stories-and-Opinions › Java-double-precision-2-decimal-places-example-float-range-math-jvm
Java double decimal precision
The precision of a double in Java is 10-324 decimal places, although true mathematical precision can suffer due to issues with binary arithmetic.
🌐
Quora
quora.com › How-do-I-round-off-a-float-to-2-decimal-points-in-Java
How to round off a float to 2 decimal points in Java - Quora
Answer (1 of 5): If you just need it for display purposes, you can do [code]String.format("%.2f", number); [/code]
🌐
Oracle
forums.oracle.com › ords › apexds › post › how-do-i-round-a-double-to-2-decimal-places-3734
how do i round a double to 2 decimal places
December 17, 2003 - hi, i want to round the result of a calculation (that is returned as a double) to 2 decimal places. which Math method do I use?
🌐
Scaler
scaler.com › home › topics › round off in java
Java Math.round() - Scaler Topics
April 19, 2024 - So, 1087.12345567 rounded to 4 decimal places is 1087.1234, and the last decimal place (4) is rounded up using the CEILING mode, resulting in 5. Hence, the output is 1087.1235. Note: We need to import the DecimalFormat and RoundingMode classes in Java using the import statement, as they are not part of the default java.lang package. Round-off is used to convert decimal values into integers. The java.lang.Math class has Math.ceil(), Math.floor(), and Math.round() methods to round off floating-point values.
🌐
Quora
quora.com › In-Java-how-do-I-round-a-number-or-variable-to-whatever-amount-of-decimal-places-I-want
In Java, how do I round a number or variable to whatever amount of decimal places I want? - Quora
Answer (1 of 7): Well this depends a bit. Do you mean that you want some text that represents the number to be to a number? Are you using a float-type (double and float in Java)? Are you using BigDecimal? Since you use the tag “Learning to Program” I’m going to assume that you, or people ...
🌐
TestMu AI Community
community.testmuai.com › ask a question
How to round a number to n decimal places in Java? - TestMu AI Community
February 3, 2025 - How can I round a number to n decimal places in Java? I need a method to round a double in Java using the half-up rounding method, meaning if the digit to be rounded is 5, it always rounds up. Additionally, I want to ensure that only significant digits are displayed—there should be no trailing ...
🌐
Baeldung
baeldung.com › home › java › java numbers › truncate a double to two decimal places in java
Truncate a Double to Two Decimal Places in Java | Baeldung
September 24, 2025 - To truncate a positive number to two decimal places, we first multiply our double by 100, moving all the numbers we want to keep in front of the decimal place. Next, we use Math.floor() to round ...
🌐
W3Docs
w3docs.com › java
round up to 2 decimal places in java?
To round a number up to two decimal places in Java, you can use the Math.ceil method and multiply the number by 100, then divide the result by 100.
🌐
ONEXT DIGITAL
onextdigital.com › home › easy ways to round doubles in java to two decimal places
Easy ways to round doubles in java to two decimal places
July 19, 2023 - The two arguments that this method accepts are “number” and “Rounding Mode” where the number is an integer value that refers to the scale to round the decimal value and the RoundingMode represents the mode of rounding the decimal value. import java.util.*; import java.lang.*; import java.io.*; import java.math.BigDecimal; import java.math.RoundingMode; public class Main { public static void main(String[] args) { double val1 = 4312.186462; System.out.println("Double value: "+val1); BigDecimal bd = new BigDecimal(val1).setScale(2, RoundingMode.HALF_UP); double val2 = bd.doubleValue(); System.out.println("Rounded Double value: "+val2); } }