Functions

round

Supported By

Syntax

[the] round of factor

round ( expression )

Factor and expression yield integers, numbers, or complexes.

Example

put round(steve) into bill

Description

The round 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 unsigned infinity, or away from zero.

The following table illustrates the behavior of the round function:

argument result
2 2
1.75 2
1.5 2
1.25 1
1 1
0.75 1
0.5 1
0.25 0
0 0
-0.25 0
-0.5 -1
-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.

Notes

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

See Also

trunc