beetlebug▾
/

tcl::mathfunc round

Gives the nearest integer to a number.

tcl::mathfunc::round NUMBER
expr {round(NUMBER)}

Description

Rounds NUMBER to the nearest integer, and a half rounds away from zero: round(2.5) is 3 and round(-2.5) is -3. The result is an integer of any size. An integer stays as it is. Inf and NaN are errors.

Arguments

ArgumentTypeDefaultDescription
NUMBERnumberrequiredAn integer or a finite float.

Returns

An integer.

Examples

% expr {round(2.5)}
3

% expr {round(-2.5)}
-3

% expr {round(1.4)}
1

% expr {round(1e20)}
100000000000000000000

Errors

% expr {round(Inf)}
integer value too large to represent
-errorcode NONE

# Tcl 9.1 only
% expr {round("x")}
cannot use non-numeric string "x" as operand of "round"
-errorcode ARITH DOMAIN {non-numeric string}

# Tcl 8.6 only
% expr {round("x")}
can't use non-numeric string as operand of "round"
-errorcode ARITH DOMAIN {non-numeric string}

Facts

Capability
None.
Tcl release
Tcl 9.1 and 8.6.
Since
ztcl 1.0.0-beta.1

See also