如方法返回类型所给定的那样,方法round返回最接近的long或int。
round() - 语法
此方法具有以下变体-
long round(double d) int round(float f)
这是参数的详细信息-
d - 一种double或float原始数据类型。
f - 浮点原始数据类型。
round() - 返回值
此方法将返回最接近的long或int(由方法的返回类型指示)到参数。
round() - 示例
public class Test { public static void main(String args[]) { double d=100.675; double e=100.500; float f=100; float g=90f; System.out.println(Math.round(d)); System.out.println(Math.round(e)); System.out.println(Math.round(f)); System.out.println(Math.round(g)); } }
这将产生以下输出-
101 101 100 90