round()四舍五入方法的简单使用

package testBlog;

public class Test {

	public static void main(String[] args) {

		System.out.println(Math.round(12.5));// round()方法四舍五入,结果为13
		System.out.println(Math.round(12.6));// round()方法四舍五入,结果为13
		System.out.println(Math.round(-12.5));// round()方法四舍五入,结果为-12
		System.out.println(Math.round(-12.4));// round()方法四舍五入,结果为-12
		System.out.println(Math.round(-12.6));// round()方法四舍五入,结果为-13

	}

}

  其中要注意的是,负数的0.5比较特殊,不会像正数的0.5一样会进位.负数的0.5不会进位.其他的进位规则就跟正数是一样的了.

原文地址:https://www.cnblogs.com/ssC2H4/p/8125511.html