目录

round()

描述 (Description)

round方法返回最接近的long或int,由方法返回类型给出。

语法 (Syntax)

此方法有以下变体 -

long round(double d)
int round(float f)

参数 (Parameters)

这是参数的细节 -

  • d - double或float原始数据类型。

  • f - 浮点原始数据类型。

返回值 (Return Value)

  • 此方法返回最接近的long或int,如方法的返回类型所示,返回参数。

例子 (Example)

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)); 
   }
}

这将产生以下结果 -

输出 (Output)

101
101
100
90
↑回到顶部↑
WIKI教程 @2018