the
floor
of
factor
floor
(
expression )
Factor and expression yield integer
s, number
s, or complex
es.
put floor(steve) into bill
The floor
function returns the given value rounded towards negative infinity. If the given value is an integer
, the given value is returned. Otherwise, the given value is rounded to the next lowest integer, regardless of sign.
The following table illustrates the behavior of the floor
function:
argument | result |
---|---|
2 | 2 |
1.75 | 1 |
1.5 | 1 |
1.25 | 1 |
1 | 1 |
0.75 | 0 |
0.5 | 0 |
0.25 | 0 |
0 | 0 |
-0.25 | -1 |
-0.5 | -1 |
-0.75 | -1 |
-1 | -1 |
-1.25 | -2 |
-1.5 | -2 |
-1.75 | -2 |
-2 | -2 |
If the given value is a complex
, the real and imaginary parts of the complex number are each rounded individually.
The following table shows the correspondences among the various roundingMethods, rounding functions, and division operators:
rounding parameter |
function | operator | java.math.RoundingMode |
---|---|---|---|
to ceiling |
ceil |
CEILING |
|
to floor |
floor |
div / mod |
FLOOR |
up / to infinity |
aug |
UP |
|
down / to zero |
trunc |
quot / rem |
DOWN |
to nearest |
round |
HALF_UP |
|
to even |
rint |
HALF_EVEN |
The following table illustrates the behavior of the rounding functions side-by-side:
argument | ceil |
floor |
aug |
trunc |
round |
rint |
---|---|---|---|---|---|---|
2 | 2 | 2 | 2 | 2 | 2 | 2 |
1.75 | 2 | 1 | 2 | 1 | 2 | 2 |
1.5 | 2 | 1 | 2 | 1 | 2 | 2 |
1.25 | 2 | 1 | 2 | 1 | 1 | 1 |
1 | 1 | 1 | 1 | 1 | 1 | 1 |
0.75 | 1 | 0 | 1 | 0 | 1 | 1 |
0.5 | 1 | 0 | 1 | 0 | 1 | 0 |
0.25 | 1 | 0 | 1 | 0 | 0 | 0 |
0 | 0 | 0 | 0 | 0 | 0 | 0 |
-0.25 | 0 | -1 | -1 | 0 | 0 | 0 |
-0.5 | 0 | -1 | -1 | 0 | -1 | 0 |
-0.75 | 0 | -1 | -1 | 0 | -1 | -1 |
-1 | -1 | -1 | -1 | -1 | -1 | -1 |
-1.25 | -1 | -2 | -2 | -1 | -1 | -1 |
-1.5 | -1 | -2 | -2 | -1 | -2 | -2 |
-1.75 | -1 | -2 | -2 | -1 | -2 | -2 |
-2 | -2 | -2 | -2 | -2 | -2 | -2 |