目录

round()

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

语法 (Syntax)

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

参数 (Parameters)

  • d - double或float原始数据类型
  • f - 浮点原始数据类型

返回值 (Return Value)

此方法返回最接近的longint ,如方法的返回类型所示,返回参数。

例子 (Example)

以下是此方法的使用示例 -

class Example { 
   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
↑回到顶部↑
WIKI教程 @2018