Convert double value to int with cast in Java
Description
The following code shows how to convert double value to int with cast.
Example
// w w w . j a v a2 s . com
public class Main {
public static void main(String[] argv) {
int a = 100;
final double FRACT = 0.7142857132857;
int c = (int)(a*FRACT);
System.out.println(FRACT + " of " + a + " is " + c);
}
}
The code above generates the following result.
Home »
Java Tutorial »
Java Data Type »
Java Tutorial »
Java Data Type »