1Double d= new Double(i);//first way
2Double d2=Double.valueOf(i);//second way
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;