[ Arithmetic | Reference Manual | Alphabetic Index ]

round(+Number, -Result)

-Result is round(+Number)

Rounds Number to the nearest integral value of the same type
Number
A number.
Result
Output: number.

Description

Rounds Number to the nearest integral value of the same type.

This operation works on all numeric types. The result value is the integral value that is closest to Number (rounding to nearest). If Number is exactly in the middle between two integers, the result is the even one.

The result type is the same as the argument type. To convert the type to integer, use integer/2.

This predicate can be used as a function in arithmetic expressions. In coroutining mode, if Number is uninstantiated, the call to round/2 is delayed until this variable is instantiated.

Modes and Determinism

Exceptions

(4) instantiation fault
Number is not instantiated (non-coroutining mode only).
(24) number expected
Number is not of a numeric type.

Examples

    Result is round(1.49).	% gives Result = 1.0
    Result is round(1.5).	% gives Result = 2.0  (odd integer part)
    Result is round(2.5).	% gives Result = 2.0
    Result is round(2.51).	% gives Result = 3.0  (even integer part)
    Result is round(3.5).	% gives Result = 4.0
    Result is round(-6.4).	% gives Result = -6.0
    Result is round(3).		% gives Result = 3

See Also

is / 2, floor / 2, ceiling / 2, truncate / 2, integer / 2