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
How to round float to 2 decimal places in Java?
A float of 2.00 is equivalent to a float of 2.0 if you tried to do ==, so that should be fine to return. If you're trying to print a float up to two decimal points you'd probably need to use a printf with %.2f More on reddit.com
🌐 r/csMajors
1
3
November 23, 2020
🌐
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
Answer (1 of 5): If you just need it for display purposes, you can do [code]String.format("%.2f", number); [/code]
🌐
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.
🌐
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.
🌐
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.
🌐
Attacomsian
attacomsian.com › blog › java-round-double-float
Round a double or float number to 2 decimal places in Java
November 26, 2022 - The Math.round() method is another way to round a double or floating point number to 2 decimal places:
🌐
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
🌐
BeginnersBook -
beginnersbook.com › home › java › how to round a number to two decimal places in java
How to round a number to two decimal places in Java
May 31, 2024 - setScale(2, RoundingMode.HALF_UP) sets the scale of the BigDecimal to 2 decimal places.RoundingMode.HALF_UP is the rounding mode that rounds towards “nearest neighbour” unless both neighbours are at equal distance, in which case it rounds up. For example, 2.555 becomes 2.56, and 2.554 becomes ...
🌐
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 “string.format()” Public class CurrencyConverter { Public static void main(String[] args) { Double amount = 123.45678; // Replace with your amount Double roundedAmount = Math.round(amount * 100.0) / 100.0; // Round the amount ...
🌐
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.
🌐
Coderanch
coderanch.com › t › 776097 › java › Rounding-decimals
Rounding decimals (Java in General forum at Coderanch)
August 17, 2023 - Since you posted in a Java forum let's assume you have the number in a Java double variable. If you want to round it to N digits you do this: 1. Multiply it by 10 to the power N 2. Add 0.5 3. Divide it by 10 to the power N Or you could follow this tutorial which I just found on line: How to ...
🌐
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