---
title: "Rounding a double in java"  
description: "Rounding a double in java"  
author: "Anonymous User"  
published: 2013-10-05  
updated: 2013-10-05  
canonical: https://www.mindstick.com/forum/1625/rounding-a-double-in-java  
category: "java"  
tags: ["java"]  
reading_time: 1 minute  

---

# Rounding a double in java

I got [project](https://www.mindstick.com/articles/105927/how-to-excel-at-managing-multiple-projects) do [convert](https://www.mindstick.com/forum/2093/configurationmanager-appsettings-convert-n-to-n-why) from cm to inch. I did it: how can i [round](https://answers.mindstick.com/qa/45311/what-was-the-agenda-of-the-round-table-conference-1930-1932) my number with Math.round?

```
public class Centimer_Inch
{
public static void main (String[] args)
{
        // 2.54cm is 1 inch
       Scanner cm = new Scanner(System.in); //Get INPUT from pc-Keyboard
       System.out.println("Enter the CM:"); // Write input
       double centimeters = cm.nextDouble();
       double inches = centimeters/2.54;
       System.out.println(inches + " Inch Is " + centimeters + " centimeters");
     }
}
```

## Replies

### Reply by Dag Hammarskjold

You can print to two decimal places using the following.

```
 System.out.printf("%.2f inch is %.2f centimeters%n", inches, centimeters);
```


---

Original Source: https://www.mindstick.com/forum/1625/rounding-a-double-in-java

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
