Encodera

Thanks for reading!

Donate to the site — we work hard for you.

Java reference

Math.floor()

Rounds down to the nearest integer that is less than or equal.

Available since: Java 1.0

Syntax

static double floor(double a)

Parameters

ParameterTypeDescription
adoubleA decimal number.

Return value

doubleA whole value as a double.

Examples

Down means towards minus infinity:

void main() {
    IO.println(Math.floor(3.7));
    IO.println(Math.floor(-3.2));
    IO.println((int) -3.7);
}

Output:

3.0
-4.0
-3

Notes

The (int) cast drops the fractional part, i.e. rounds towards zero: for negative numbers that differs from floor(). The result of floor() is a double; cast it to get an int.

See also

  • Math.ceil() — Rounds up to the nearest integer that is greater than or equal.
  • Math.round() — Rounds a number to the nearest integer.
  • Math.floorMod() — A remainder that always has the sign of the divisor.

Related recipes

In the tutorial

  • Type conversion — Automatic widening, explicit (int) casts, turning strings into numbers with Integer.parseInt and numbers into strings.

Thanks for reading!

Donate to the site — we work hard for you.