I have the following two calculation using Math.round(...):

```
double x = 0.57145732;
x = x * 100;
x = Math.round(x * 10);
x = x / 10;

```

If I now print the value of x it will show me: 57.1.

```
double x = 0.57145732;
x = (Math.round((x * 100) * 10)) / 10;
// x = (Math.round(x * 1000)) / 10; //Also gives me 57.0.

```

If I now print the value of x it will show me: 57.0.

Why is there this difference in the outcome?
['https://Stackoverflow.com/questions/39326512', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/587261/']
The `Math.round()` method returns an **integer** (of type `long` - as pointed out by [Ole V.V](https://stackoverflow.com/users/5772882/ole-v-v)). It's usually thought to return a `float` or `double` which gives rise to confusions as these.

In the second calculation,

```
Math.round((x * 100) * 10)

```

returns `571`. Now, this value and `10` both are integers (571 is long, 10 is int). So when the calculation takes the form

```
x = 571 / 10

```

where x is double, `571/10` returns `57` instead of `57.1` since it is `int`. Then, `57` is converted to double and it becomes `57.0`

If you do

```
x = (double)Math.round((x * 100) * 10) / 10.0;

```

its value becomes `57.1`.

---

**Edit**: There are two versions of the `Math.round()` function. The one you used accepts a double (since x is double) and returns `long`. In your case, **implicit type casting** spares you the trouble of considering the precise little details.
This because Math.round() returns an int. If you do this step-by-step (as in the first example), you assign the result of Math.round() to a float value. The following calculation uses then a float division.

In the second example, you let the JVM decide which types to use (and it uses an integer division as the intermediate step). This is why the precision gets lost.