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
🌐
W3Schools
w3schools.com › java › ref_math_round.asp
Java Math round() Method
System.out.println(Math.round(0.60)); ...ntln(Math.round(-5.1)); System.out.println(Math.round(-5.9)); ... The round() method rounds a number to the nearest integer....
🌐
Programiz
programiz.com › java-programming › library › math › round
Java Math round()
The round() method takes a single parameter. ... Note: The data type of the value should be either float or double. ... class Main { public static void main(String[] args) { // Math.round() method // value greater than 5 after decimal double a = 1.878;
🌐
GeeksforGeeks
geeksforgeeks.org › java › java-math-round-method
Java Math round() Method - GeeksforGeeks
May 13, 2025 - Example 2: In this example, we will see how the round() method handles all the special cases. ... // 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)); } }
🌐
Tutorialspoint
tutorialspoint.com › java › number_round.htm
Java - round() Method
public class Test { public static void main(String args[]) { double d = 100.675; double e = 100.500; float f = 100; float g = 90f; System.out.println(Math.round(d)); System.out.println(Math.round(e)); System.out.println(Math.round(f)); System.out.println(Math.round(g)); } } This will produce the following result − · 101 101 100 90 · java_numbers.htm ·
🌐
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 up to specific decimal places, in this case 2 decimal places we multiply 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, ...
🌐
Tutorial Gateway
tutorialgateway.org › java-math-round-function
Java Math.round Function
March 28, 2025 - First, we declared a variable of type Double and performed the round function directly on the expression. double a = Math.round(10.9666 - 14.9865 + 154.9852);
🌐
Tutorialspoint
tutorialspoint.com › java › lang › math_round_float.htm
Java - Math round(float x) method
package com.tutorialspoint; public class MathDemo { public static void main(String[] args) { // get float numbers float x = -0.0f; float y = 0.0f; // find the long for these float number System.out.println("Math.round(" + x + ")=" + Math.round(x)); System.out.println("Math.round(" + y + ")=" + Math.round(y)); } } Let us compile and run the above program, this will produce the following result − · Math.round(-0.0)=0 Math.round(0.0)=0 · java_lang_math.htm ·
Find elsewhere
🌐
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!
🌐
Javatpoint
javatpoint.com › java-math-round-method
Java Math.round() method with Examples - Javatpoint
Java Math.round() method with Examples on abs(), min(), max(), avg(), round(), ceil(), floor(), pow(), sqrt(), sin(), cos(), tan(), exp() etc.
🌐
Vultr Docs
docs.vultr.com › java › standard-library › java › lang › Math › round
Java Math round() - Round Decimal Value | Vultr Docs
December 3, 2024 - Discover the nuances between rounding double and float datatypes and explore practical examples to solidify your understanding of this method. Declare a float variable. Apply the Math.round() method.
🌐
CodeGym
codegym.cc › java blog › java math › math round() method in java
Math round() method in Java
April 2, 2025 - Value argument could be float or double. The method returns the nearest int (in case of float value) or long (in case of double value) number to the argument, with ties rounding to positive infinity.
🌐
GeeksforGeeks
geeksforgeeks.org › java-math-round-method-example
Java Math round() method with Example - GeeksforGeeks
April 11, 2018 - Example 2: In this example, we will see how the round() method handles all the special cases. ... // 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)); } }
🌐
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 learn how to round a number to n 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 is typically the way to go.
🌐
Scaler
scaler.com › home › topics › round off in java
Java Math.round() - Scaler Topics
April 19, 2024 - Example: 9.2 will be rounded off to 9. Note: The above trick is for positive numbers; it will be vice versa for negative numbers. ... Apart from using the Math class in Java, there are other ways to round a number. One of those methods is the format() method in Java.
🌐
LabEx
labex.io › tutorials › java-rounding-floating-point-numbers-in-java-117452
Java Rounding Techniques | Programming Tutorials | LabEx
The following method takes a decimal ... number. public static double round(double num, int places) { double scale = Math.pow(10, places); double roundedNum = Math.round(num * scale) / scale; return roundedNum; } public static ...
🌐
BeginnersBook
beginnersbook.com › 2022 › 10 › java-math-round-method
Java Math.round() Method
public class JavaExample { public static void main(String[] args) { double d = 15.75; float f = -7.6f; // closest long value when rounding off double System.out.println(Math.round(d)); //closest int value when rounding off float System.out.println(Math.round(f)); } }
🌐
Medium
medium.com › @AlexanderObregon › rounding-numbers-with-math-round-math-floor-and-math-ceil-in-java-d201bbeb85e2
Java’s Math Rounding Methods Explained | Medium
March 7, 2025 - When rounding functions process ... Math.round() method follows a common rounding rule: if the decimal portion is 0.5 or greater, the number rounds up; otherwise, it rounds down....
🌐
CodeAhoy
codeahoy.com › java › Math-Round-method-JI_16
Java Math.round() with Examples | CodeAhoy
October 12, 2019 - Learn how to Math.round() in Java to round a decimal to its nearest integer.