You could do something like this:

CopyDouble.valueOf(new DecimalFormat("#.##").format(
                                           centimeters)));  // 2 decimal-places

If you really wanted Math.round:

Copy(double)Math.round(centimeters * 100) / 100  // 2 decimal-places

You can have 3 decimal places by using 1000, 4 by using 10000 etc. I personally like the first option more.

Answer from arshajii on Stack Overflow
🌐
Oracle
docs.oracle.com › javase › 8 › docs › api › java › lang › Math.html
Math (Java Platform SE 8 )
October 20, 2025 - Returns the correctly rounded positive square root of a double value. Special cases: If the argument is NaN or less than zero, then the result is NaN. If the argument is positive infinity, then the result is positive infinity. If the argument is positive zero or negative zero, then the result is the same as the argument. Otherwise, the result is the double value closest to the true mathematical square root of the argument value.
🌐
Programiz
programiz.com › java-programming › library › math › round
Java Math round()
Try Programiz PRO! ... The round() method rounds the specified value to the closest int or long value and returns it. That is, 3.87 is rounded to 4 and 3.24 is rounded to 3. class Main { public static void main(String[] args) { double a = 3.87; System.out.println(Math.round(a)); } } // Output: 4
🌐
Educative
educative.io › answers › how-to-use-the-java-mathround-method
How to use the Java Math.round() method
If we want to round a decimal number ... it by 100.0 , pass it to the Math.round() method and then divide it by 100.0. Note: To round a number to a specific decimal place, multiply it by ... Kickstart your programming journey with "Learn Java."...
🌐
GeeksforGeeks
geeksforgeeks.org › java › java-math-round-method
Java Math round() Method - GeeksforGeeks
May 13, 2025 - // Java program to demonstrate the working // of Math.round() method for special cases import java.lang.Math; class Geeks { // driver code public static void main(String args[]) { // float numbers float x = 4567.9874f; // find the closest long for these floats System.out.println(Math.round(x)); float y = -3421.134f; // find the closest long for these floats System.out.println(Math.round(y)); double p = Double.POSITIVE_INFINITY; // returns the Long.MAX_VALUE value when System.out.println(Math.round(p)); } } Output ·
🌐
Oracle
docs.oracle.com › javase › › 7 › docs › api › java › lang › Math.html
Math (Java Platform SE 7 )
Return d × 2scaleFactor rounded as if performed by a single correctly rounded floating-point multiply to a member of the double value set. See the Java Language Specification for a discussion of floating-point value sets. If the exponent of the result is between Double.MIN_EXPONENT and Double.MAX_EXPONENT, the answer is calculated exactly.
🌐
W3Schools
w3schools.com › java › ref_math_round.asp
Java Math round() Method
assert abstract boolean break byte case catch char class continue default do double else enum exports extends final finally float for if implements import instanceof int interface long module native new package private protected public return requires short static super switch synchronized this throw throws transient try var void volatile while Java String Methods
🌐
Dot Net Perls
dotnetperls.com › math-round-java
Java - Math.round Method - Dot Net Perls
Result The Math.round method changes 10.1 to 10, and 10.5 to 11. So it rounds down and up depending on the number's fractional value. import java.lang.Math; public class Program { public static void main(String[] args) { double[] values = {
Find elsewhere
🌐
Tutorialspoint
tutorialspoint.com › java › lang › math_round_float.htm
Java - Math round(float x) method
The java.lang.Math.round(float a) returns the closest int to the argument. The result is rounded to an integer by adding 1/2, taking the floor of the result, and casting the result to type int. Special cases ?
🌐
GeeksforGeeks
geeksforgeeks.org › java-math-round-method-example
Java Math round() method with Example - GeeksforGeeks
April 11, 2018 - // Java program to demonstrate the working // of Math.round() method for special cases import java.lang.Math; class Geeks { // driver code public static void main(String args[]) { // float numbers float x = 4567.9874f; // find the closest long for these floats System.out.println(Math.round(x)); float y = -3421.134f; // find the closest long for these floats System.out.println(Math.round(y)); double p = Double.POSITIVE_INFINITY; // returns the Long.MAX_VALUE value when System.out.println(Math.round(p)); } } Output ·
🌐
Know Program
knowprogram.com › home › math.round() method in java
Math.round() Method in Java - Know Program
September 7, 2022 - But if we want to import only the round() method of the Math class, not another static method and variables of the Math class then we can use the “import static java.lang.Math.round;” statement.
🌐
Javatpoint
javatpoint.com › java-math-round-method
Java Math.round() method with Examples - Javatpoint
Java CopyOnWriteArrayList · indexOf() lastIndexOf() clone() toArray() Math.abs() Math.max() Math.min() Math.round() Math.sqrt() Math.cbrt() Math.pow() Math.signum() Math.ceil() Math.copySign() Math.nextAfter() Math.nextUp() Math.nextDown() Math.floor() Math.floorDiv() Math.random() Math.rint() Math.hypot() Math.ulp() Math.getExponent() Math.IEEEremainder() Math.addExact() Math.subtractExact() Math.multiplyExact() Math.incrementExact() Math.decrementExact() Math.negateExact() Math.toIntExact() Math.log() Math.log10() Math.log1p() Math.exp() Math.expm1() Math.sin() Math.cos() Math.tan() Math.asin() Math.acos() Math.atan() Math.sinh() Math.cosh() Math.tanh() Math.toDegrees ·
🌐
Scaler
scaler.com › home › topics › round off in java
Java Math.round() - Scaler Topics
April 19, 2024 - Math.round() is one of the many built-in Java methods that allows you to round a floating-point number to the nearest whole number.
🌐
Programiz
programiz.com › java-programming › library › math › floor
Java Math floor()
That is, the value 3.8 will be rounded to 3.0 which is equal to integer 3. class Main { public static void main(String[] args) { double a = 3.8; System.out.println(Math.floor(a)); } } // Output: 3.0 ... Here, floor() is a static method. Hence, we are accessing the method using the class name, Math.
🌐
Tutorial Gateway
tutorialgateway.org › java-math-round-function
Java Math.round Function
March 28, 2025 - If you observe the code snippet, we used the Math round Function directly inside the System.out.format statement. Here, the compiler will call the long method to find the corresponding closest values and print the output. package MathFunctions; import java.util.ArrayList; public class RoundMethodOnList { public static void main(String[] args) { ArrayList<Double> myList = new ArrayList<Double>(5); myList.add(-15.289); myList.add(-15.65); myList.add(25.986); myList.add(40.499); myList.add(40.589); for (double x : myList) { System.out.println(Math.round(x)); } } }
🌐
w3resource
w3resource.com › java-exercises › math › java-math-exercise-4.php
Java - Round a float number to specified decimals
Sample Solution: Java Code: import java.lang.*; import java.math.BigDecimal; public class Example4 { public static void main(String[] args) { float x = 451.3256412f; BigDecimal result; int decimal_place = 4; BigDecimal bd_num = new ...
🌐
Codecademy
codecademy.com › docs › java › math methods › .round()
Java | Math Methods | .round() | Codecademy
October 24, 2022 - The Math.round() method returns an int or long value that is closest to the number provided. ... Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more! ... Learn to code in Java — a robust programming language used to create software, web and mobile apps, and more.
🌐
Microsoft Learn
learn.microsoft.com › en-us › dotnet › api › java.lang.math.round
Math.Round Method (Java.Lang) | Microsoft Learn
Java.Lang · Assembly: Mono.Android.dll · Important · Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here. Returns the closest long to the argument, with ties rounding to positive infinity.
🌐
CodeGym
codegym.cc › java blog › java math › math round() method in java
Math round() method in Java
April 2, 2025 - double: A double-precision 64-bit floating-point value. This parameter type is used for rounding larger or more precise decimal numbers. Both overloads of Math.round() return the rounded result as an integer type, but there is a key distinction in the return type based on the input:
🌐
Xenovation
xenovation.com › home › blog › java › rounding number in java
Rounding Number in Java | XENOVATION
April 6, 2019 - The Java language provides a static round method from the java.lang.Math class. The round method is an overloaded method with the following signatures. ... The rounding method returns the nearest number based on the argument. package ...