ITeye博客

对数字进行四舍五入的方法

windy_star · 2010-12-28 16:35 · java基础 · 编程语言 · Java · Markdown

使用Math中的round方法


import java.util.*;

public class qwe {
	public static void main(String[] args) {
		double above = 0.7, below = 0.4;
		float fabove = 0.7f, fbelow = 0.4f;

		System.out.println("Math.round(above)" + Math.round(above));
		System.out.println("Math.round(above)" + Math.round(below));
		System.out.println("Math.round(above)" + Math.round(fabove));
		System.out.println("Math.round(above)" + Math.round(fbelow));

	}

}


结果为:1 0 1 0

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。