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

  


原文地址:https://www.cnblogs.com/bluestorm/p/2298123.html