📜  Java Math floor()

📅  最后修改于: 2020-09-27 01:01:43             🧑  作者: Mango

Java Math floor()方法向下舍入指定的double值并将其返回。

取整后的值将等于数学整数。也就是说,值3.8将四舍五入为等于整数3的 3.0

floor()方法的语法为:

Math.floor(double value)

在这里, floor()是静态方法。因此,我们使用类名Math来访问该方法。


floor()参数

floor()方法采用单个参数。

  • -要向上舍入的数字

floor()返回值
  • 返回等于数学整数的舍入值

注意 :返回的值是小于或等于指定参数的最大值。


示例:Java Math.floor()
class Main {
  public static void main(String[] args) {

    // Math.floor() method
    // value greater than 5 after decimal
    double a = 1.878;
    System.out.println(Math.floor(a));  // 1.0

    // value equals to 5 after decimal
    double b = 1.5;
    System.out.println(Math.floor(b));  // 1.0

    // value less than 5 after decimal
    double c = 1.34;
    System.out.println(Math.floor(c));  // 1.0
  }
}

推荐的教程

  • Math.ceil()
  • Math.round()