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
🌐
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 - n: number of decimal places · number: value to be rounded · Java · class GFG { public static void main(String[] args) { double number = 3.141341435; System.out.format("%.2f", number); } } Output · 3.14 · DecimalFormat is a subclass of NumberFormat used for formatting decimal numbers with custom patterns.
Discussions

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
Decimal with 2 digits without round off | OutSystems
I need decimal value with 2 decimal places for the amount and it should not be rounded instead it should be cut off to 2 decimal places · Example: 4816.875 should display as 4816.87 or 3699.095 should display as 3699.09 More on outsystems.com
🌐 outsystems.com
August 11, 2023
Show only 2 decimal points from double
Hello, I have diferent decimal numbers in double format. I would like That only whole number and two decimal places was shown. More on forum.uipath.com
🌐 forum.uipath.com
1
0
March 6, 2023
I want to round a decimal number, for example 2100.000000, to two digits after the decimal dot, even if it's two 0s.
You will not be able to format the value inside a double variable. You can round it, but you cant cut off additional 0's at the end. 2100.000000 is the same as 2100.00 from a numeric perspective. You can however format the double into a String as you already did yourself with the formatted variable. Either use the DecimalFormat or String.format. More on reddit.com
🌐 r/javahelp
13
4
February 15, 2023
🌐
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
You can use the Java DecimalFormat class to define a format pattern that rounds numbers to a specific number of decimal places for display. The following example creates a DecimalFormat object with the format pattern #.## (where # represents digits) to round the number to 2 decimal places:
🌐
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 Apache Common library, Math.round(), BigDecimal using the setScale() method, and other tools may all round a double number to two decimal places. Commonly used by programmers “round()” method to round two decimal places to discover ...
🌐
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 - These unexpected results occur because primitive types like float and double use binary representations, which can’t exactly represent some decimal values. As a result, rounding with these types can lead to subtle truncation or rounding errors. For example, the value 260.775 cannot be exactly represented as a double. Internally, it might be stored as slightly less than 260.775, so rounding it to two decimal places results in 260.77 instead of 260.78.
Find elsewhere
🌐
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
Java Application Developm... ... Use one of these approaches depending on purpose: display formatting, exact decimal arithmetic, or numeric rounding for storage. ... String s = df.format(value); Both produce a string with two decimal places and handle trailing zeros. 2) For rounding to a double/float value (binary floating-point; may produce inexact decimal representation)
🌐
TheServerSide
theserverside.com › blog › Coffee-Talk-Java-News-Stories-and-Opinions › Format-double-Java-printf-example
How to format a Java double with printf example
It is a common requirement to format currencies to two decimal places. You can easily achieve this with the Java printf function. Just use %.2f as the format specifier.
🌐
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.
🌐
CoreUI
coreui.io › blog › how-to-round-a-number-to-two-decimal-places-in-javascript
How to round a number to two decimal places in JavaScript · CoreUI
February 21, 2024 - The key to rounding to 2 decimal places is to manipulate the number such that the function applies rounding at the correct decimal position, as illustrated through the methods above. How do you round numbers in JavaScript without built-in methods?
🌐
OutSystems
outsystems.com › forums › discussion › 90504 › decimal-with-2-digits-without-round-off
Decimal with 2 digits without round off | OutSystems
August 11, 2023 - I need decimal value with 2 decimal places for the amount and it should not be rounded instead it should be cut off to 2 decimal places · Example: 4816.875 should display as 4816.87 or 3699.095 should display as 3699.09
🌐
JanBask Training
janbasktraining.com › community › java › how-can-i-utilize-java-for-round-to-2-decimal-places
How can I utilize Java for round to 2 decimal places? | JanBask Training Community
December 22, 2023 - Using “DecimalFormat” Import java.text.DecimalFormat; Public class CurrencyConverter { Public static void main(String[] args) { Double amount = 123.45678; // Replace with your amount DecimalFormat df = new DecimalFormat(“#.##”); // Define the decimal format Df.setRoundingMode(RoundingMode.HALF_UP); // Set the rounding mode Double roundedAmount = Double.parseDouble(df.format(amount)); // Round the amount System.out.println(“Rounded amount: “ + roundedAmount); } }
🌐
Scaler
scaler.com › home › topics › round off in java
Java Math.round() - Scaler Topics
April 19, 2024 - For example, %f stands for a floating-point number, and we can provide precision for the decimal value using %.4f, which means the output should be a floating-point number rounded to 4 decimal places. In the Java String format() method, we can specify the expected output format. Now, let's see how we can use this method to round off a floating-point number in Java. ... In the above program, the format() method is used to print the given floating-point number number to 2 decimal places.
🌐
John Dalesandro
johndalesandro.com › blog › rounding-decimals-in-java-avoiding-round-off-errors-with-bigdecimal
Rounding Decimals in Java: Avoiding Round-Off Errors with BigDecimal
March 21, 2025 - This is the recommended method for rounding decimals in Java. BigDecimal handles large and small numbers without round-off errors, ensuring precise results. Method 4: Rounded using BigDecimal Input value: 3.14159265358979323846264338327950288419716939937510 -------- Rounded to 0 decimal places: 3 Rounded to 1 decimal places: 3.1 Rounded to 2 decimal places: 3.14 Rounded to 3 decimal places: 3.142 Rounded to 4 decimal places: 3.1416 Rounded to 5 decimal places: 3.14159 Rounded to 6 decimal places: 3.141593 Rounded to 7 decimal places: 3.1415927 Rounded to 8 decimal places: 3.14159265 Rounded to
🌐
Mkyong
mkyong.com › home › java › java – display double in 2 decimal places
Java - Display double in 2 decimal places - Mkyong.com
October 29, 2021 - package com.mkyong.math.rounding; import java.math.RoundingMode; import java.text.DecimalFormat; public class DecimalExample { private static final DecimalFormat df = new DecimalFormat("0.00"); public static void main(String[] args) { double input = 3.14159265359; System.out.println("double : " + input); System.out.println("double : " + df.format(input)); //3.14 // DecimalFormat, default is RoundingMode.HALF_EVEN df.setRoundingMode(RoundingMode.DOWN); System.out.println("\ndouble (RoundingMode.DOWN) : " + df.format(input)); //3.14 df.setRoundingMode(RoundingMode.UP); System.out.println("double (RoundingMode.UP) : " + df.format(input)); //3.15 } }
🌐
Verve AI
vervecopilot.com › interview-questions › what-does-mastering-java-round-double-to-2-decimal-places-reveal-about-your-professional-aptitude
What Does Mastering Java Round Double To 2 Decimal Places Reveal About Your Professional Aptitude?
The importance of numerical precision extends far beyond the confines of a coding challenge. In technical assessments, getting java round double to 2 decimal places correct is often a baseline requirement for tasks involving financial calculations, data analysis, or even display logic for user interfaces.
🌐
DataCamp
datacamp.com › tutorial › python-round-to-two-decimal-places
How to Round to 2 Decimal Places in Python | DataCamp
August 8, 2024 - Learn how to round a number to 2 decimal places in Python for improved precision using techniques like round(), format(), and string formatting techniques.
🌐
W3Schools
w3schools.com › java › java_data_types_numbers.asp
Java Numbers
You should use a floating point type whenever you need a number with a decimal, such as 9.99 or 3.14515.