beetlebug▾
/

tcl::mathfunc truncTcl 9.1 only

Gives the integer part of a number, as a float.

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

Description

Cuts the fraction part off NUMBER, toward zero, and gives a float. trunc(-0.5) is -0.0, and trunc(Inf) is Inf. For an integer result, use entier.

Arguments

ArgumentTypeDefaultDescription
NUMBERnumberrequiredAny number.

Returns

A float with no fraction part, or an infinity.

Examples

% expr {trunc(-2.5)}
-2.0

% expr {trunc(2.7)}
2.0

% expr {trunc(-0.5)}
-0.0

% tcl::mathfunc::trunc 3.5
3.0

Errors

% expr {trunc("a")}
expected floating-point number but got "a"
-errorcode TCL VALUE NUMBER

% expr {trunc(NaN)}
floating point value is Not a Number
-errorcode TCL VALUE DOUBLE NAN

Facts

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

See also