the
rint
of
factor
rint
(
expression )
Factor and expression yield integer
s, number
s, or complex
es.
put rint(steve) into bill
The rint
function returns the given value rounded towards the nearest integer. If the given value is an integer
, the given value is returned. Otherwise, the given value is rounded to the nearest integer. If the fractional part of the given value is exactly .5, the given value is rounded towards the nearest even number.
The following table illustrates the behavior of the rint
function:
argument | result |
---|---|
2 | 2 |
1.75 | 2 |
1.5 | 2 |
1.25 | 1 |
1 | 1 |
0.75 | 1 |
0.5 | 0 |
0.25 | 0 |
0 | 0 |
-0.25 | 0 |
-0.5 | 0 |
-0.75 | -1 |
-1 | -1 |
-1.25 | -1 |
-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 |