May be this is silly question. I want to get rid of the fractional part of the Double
number. But I cant do that. It shows the error that incompatible types. What to do?
Double to int
conversion in one line....please help thanks
This question is related to
java
int average_in_int = ( (Double) Math.ceil( sum/count ) ).intValue();
double myDb = 12.3;
int myInt = (int) myDb;
Result is: myInt = 12
try casting the value
double d = 1.2345;
long l = (long) d;
All other answer are correct, but remember that if you cast double to int you will loss decimal value.. so 2.9 double become 2 int.
You can use Math.round(double)
function or simply do :
(int)(yourDoubleValue + 0.5d)
Source: Stackoverflow.com