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 Top answer 1 of 12
592
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.
2 of 12
121
double d = 2.34568;
DecimalFormat f = new DecimalFormat("##.00");
System.out.println(f.format(d));
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.
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
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
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
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
Videos
Reddit
reddit.com › r/learnprogramming › truncate to 2 decimal places in java
r/learnprogramming on Reddit: Truncate to 2 decimal places in Java
December 22, 2021 -
Hi, how do i truncate the result of a calculation to 2 decimals; for instance if the result is 19.899 or 19.892 i want the system to print 19.89 regardless. Thanks and merry christmas:))
Top answer 1 of 3
2
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).
2 of 3
1
Update: This does not answer the question since it will round the result. System.out.printf("%.2f", result);
Mkyong
mkyong.com › home › java › java – how to round double / float value to 2 decimal places
Java – How to round double / float value to 2 decimal places - Mkyong.com
February 25, 2025 - We can use DecimalFormat("0.00") or BigDecimal to round float / double to 2 decimal places.
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.
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.
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 ...
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