java Math.round()
public class MathTest {
public static void main(String[] args) {
// TODO Auto-generated method stub
//Math.round():四舍五入运算
System.out.println( "1.小数点后第一位 =5" );
System.out.println( "正数:Math.round(11.5) = " + Math.round( 11.5 ));
System.out.println( "负数:Math.round(-11.5) = " + Math.round(- 11.5 ));
System.out.println( "2.小数点后第一位 <5" );
System.out.println( "正数:Math.round(11.49) = " + Math.round( 11.49 ));
System.out.println( "负数:Math.round(-11.49) = " + Math.round(- 11.49 ));
System.out.println( "3.小数点后第一位 >5" );
System.out.println( "正数:Math.round(11.69) = " + Math.round( 11.69 ));
System.out.println( "负数:Math.round(-11.61) = " + Math.round(- 11.69 ));
System.out.println( "总结:正数小数点后大于5则舍入,负数小数点后小于以及等于5都舍去,反之舍入" );
System.out.println( "也就是说:小数点后大于5全部加,等于5正数加,小于5全不加" );
}
public class Main {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
int a=Math.round(11.5f);
System.out.println(a);
long b=Math.round(-11.5);
System.out.println(b);
}
}
/*
12
-11
*/
public class MthRound {
public static void main(String[] args) throws Exception {
//int i=Math.round(11.5);
System.out.println(Math.round(11.5));
//int j=Math.round(-11.5);
System.out.println(Math.round(-11.5));
System.out.println(Math.round(-11.4));
System.out.println(Math.round(-11.6));
}
}
/*
12
-11
-11
-12
*/