English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Java Basic Tutorial

Java flow control

Java array

Java object-oriented (I)

Java object-oriented (II)

Java object-oriented (III)

Java Exception Handling

Java List

Java Queue (queue)

Java Map collection

Java Set collection

Java input and output (I/O)

Java Reader/Writer

Java other topics

Java Math floor() usage and example

Java Math Mathematical Methods

The Java Math floor() method rounds down the specified double value and returns it.

The integer part should be equal to a mathematical integer. That is, the value3.8Should be rounded to3.0, equal to an integer3.

The syntax of the floor() method is:

Math.floor(double value)

Note: floor() is a static method. Therefore, we can access this method using the class name Math.

floor() parameter

  • value - The number to be rounded up

floor() return value

  • Returns the rounded value equal to a mathematical integer

Note: The returned value should be the largest value that is greater than or equal to the specified parameter.

Example: Java Math.floor()

class Main {
  public static void main(String[] args) {
    //Math.Floor() Method.
    //is greater than the decimal point5The value
    double a = 1.878;
    System.out.println(Math.floor(a));  // 1.0
    //The value after the decimal point is equal to5
    double b = 1.5;
    System.out.println(Math.floor(b));  // 1.0
    //is less than the decimal point5The value
    double c = 1.34;
    System.out.println(Math.floor(c));  // 1.0
  }
}

Recommended Tutorials

Java Math Mathematical Methods