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

JAVA学习网 2017-12-27 22:51:02
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不会进位.其他的进位规则就跟正数是一样的了.

阅读(775) 评论(0)