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
round() method converts the double to an integer by rounding off the number to the nearest integer. For example – 10.6 will be converted to 11 using Math. round() method and 1ill be converted to 10 using typecasting or Double. intValue() method.
Answer: In Java, the primitive data type double can be converted to primitive data type int using the following Java class methods and ways: typecasting: typecast to int. Math. round()
If you really should use Double instead of double you even can get the int Value of Double by calling:
Double d = new Double(1.23); int i = d.intValue();
Else its already described by Peter Lawreys answer.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With