Home United States USA — software How To Convert double To int In Java?

How To Convert double To int In Java?

221
0
SHARE

Have a double and you want it as int in your Java program? Check this article to learn how you can convert double to int in Java.
Join the DZone community and get the full member experience. In this article, we will see how we can convert a double to an int. In Java programming, you will have a double primitive value (ex 82.14), but to do the further operations you need an int value (ex.82) so let’s see how to convert double to int in Java. There are three ways you can convert double to int. I will list them all below and, then we will see them one by one. We know double is a 64-bit primitive value, and int is a 32-bit primitive value. So, to convert double to int, we can downcast the double value to int. I have given a simple example below that shows to convert double to int using typecasting. Output: The problem with the typecasting is that it will truncate the value after the decimal point. It will not round it. In the case of 82.14, we will get an int value of 82, which looks ok. But when we have a double value like 82.

Continue reading...