You need to explicitly get the int value using method intValue() like this:
Double d = 5.25;
Integer i = d.intValue(); // i becomes 5
Or
double d = 5.25;
int i = (int) d;
More Related Contents:
- Why don’t Java’s +=, -=, *=, /= compound assignment operators require casting?
- Downcasting in Java
- Convert String to double in Java
- casting Object array to Integer array error
- Does Java casting introduce overhead? Why?
- Why does the ternary operator unexpectedly cast integers?
- Why does Java implicitly (without cast) convert a `long` to a `float`?
- java: How can I do dynamic casting of a variable from one type to another?
- How to cast a double to an int in Java by rounding it down?
- Most efficient way to cast List to List
- Primitive type ‘short’ – casting in Java
- Why do we assign a parent reference to the child object in Java?
- Cast Int to enum in Java
- Dealing with an ArrayStoreException
- How are integers cast to bytes in Java?
- Postgres data type cast
- Explicit type casting example in Java
- Can’t cast to to unspecific nested type with generics
- How does the Java cast operator work?
- How does double to int cast work in Java
- How to cast an Object to an int
- How to have Java method return generic list of any type?
- Casting an array of Objects into an array of my intended class
- Cannot convert from List to List
- Casting to generic type in Java doesn’t raise ClassCastException?
- Java rules for casting
- Casting rules for primitive types in java
- Differences in auto-unboxing between Java 6 vs Java 7
- How does long to int cast work in Java?
- Cast via reflection and use of Class.cast() [duplicate]