package valueTest;
public class Double2Int {
/**
* @param args
*/
public static void main(String[] args) {
/**
* double d
*/
System.out.println("double d ");
//d>0
double d = 5.5;
int i = (int)d;
System.out.println("d>0: " + i);
System.out.println("Math.floor(i): " + Math.floor(d)+ "\n");
d = 5.9;
i = (int)d;
System.out.println("d>0: " + i);
System.out.println("Math.floor(i): " + Math.floor(d)+ "\n");
d = 5.2;
i = (int)d;
System.out.println("d>0: " + i);
System.out.println("Math.floor(i): " + Math.floor(d) + "\n");
//d<0
d = -5.5;
i = (int)d;
System.out.println("d<0: " +i);
System.out.println("Math.floor(i): " + Math.floor(d)+ "\n");
d = -5.9;
i = (int)d;
System.out.println("d<0: " +i);
System.out.println("Math.floor(i): " + Math.floor(d)+ "\n");
d = -5.2;
i = (int)d;
System.out.println("d<0: " +i);
System.out.println("Math.floor(i): " + Math.floor(d)+ "\n");
System.out.println("\n\nDouble d ");
/**
* 换成大写Double
*/
//d>0
Double d1 = new Double(5.5) ;
int i1 = d1.intValue() ;
System.out.println("d>0: " + i1);
System.out.println("Math.floor(i): " + Math.floor(d)+ "\n");
d1 = new Double(5.9) ;
i1 = d1.intValue() ;
d1 = new Double(5.2) ;
i1 = d1.intValue() ;
System.out.println("d>0: " +i1);
System.out.println("Math.floor(i): " + Math.floor(d)+ "\n");
//d<0
d1 = new Double(-5.5) ;
i1 = d1.intValue() ;
System.out.println("d<0: " + i1);
System.out.println("Math.floor(i): " + Math.floor(d)+ "\n");
d1 = new Double(-5.9) ;
i1 = d1.intValue() ;
System.out.println("d<0: " +i1);
System.out.println("Math.floor(i): " + Math.floor(d)+ "\n");
d1 = new Double(-5.2) ;
i1 = d1.intValue() ;
System.out.println("d<0: " +i1);
System.out.println("Math.floor(i): " + Math.floor(d)+ "\n");
}
}
结果:
double d
d>0: 5
Math.floor(i): 5.0
d>0: 5
Math.floor(i): 5.0
d>0: 5
Math.floor(i): 5.0
d<0: -5
Math.floor(i): -6.0
d<0: -5
Math.floor(i): -6.0
d<0: -5
Math.floor(i): -6.0
Double d
d>0: 5
Math.floor(i): -6.0
d>0: 5
Math.floor(i): -6.0
d<0: -5
Math.floor(i): -6.0
d<0: -5
Math.floor(i): -6.0
d<0: -5
Math.floor(i): -6.0