# [ACCEPTED]-How to convert Double to int directly?-java

Accepted answer

If you really should use Double instead 3 of double you even can get the int Value 2 of Double by calling:

```
Double d = new Double(1.23);
int i = d.intValue();
```

Else its already described 1 by Peter Lawreys answer.

All other answer are correct, but remember 4 that if you cast double to int you will 3 loss decimal value.. so 2.9 double become 2 2 int.

You can use `Math.round(double)`

function or simply do 1 :

```
(int)(yourDoubleValue + 0.5d)
```

```
double myDb = 12.3;
int myInt = (int) myDb;
```

Result is: myInt = 12

0

try casting the value

```
double d = 1.2345;
long l = (long) d;
```

0

```
int average_in_int = ( (Double) Math.ceil( sum/count ) ).intValue();
```

0

Source:
stackoverflow.com

More Related questions

Cookie Warning

We use cookies to improve the performance of the site. By staying on our site, you agree to the terms of use of cookies.