1class DoubleToInt {
2 public static void main( String args[] ) {
3 double DoubleValue = 3.6987;
4 int IntValue = (int) DoubleValue;
5 System.out.println(DoubleValue + " is now " + IntValue);
6 }
7}
1class Scratch{
2 public static void main(String[] args){
3 double decimal = 5.7;
4 System.out.println( (int) decimal ); //casting
5 System.out.println( Math.round(decimal * 10) / (double) 10); //Math.round()
6 System.out.println( decimal % 1); // modulus
7 System.out.println( Integer.parseInt( String.valueOf(decimal).substring(0, String.valueOf(decimal).indexOf(".")))); // .substring()
8 }
9}
1//In java, you can cast to any primitive type by putting (primitiveType)
2//before whatever you're casting to.
3
4private static int myInt = (int)myDouble;