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全不加");
	}

 

  


posted @ 2011-11-18 16:11  petercao  阅读(2715)  评论(1编辑  收藏  举报