I've thought of :
scan $float %d int
but there sure must be a straighter way...
Bruno.
-----------------------------------------------------------------------
Bruno SERRA | " Please do not be alarmed.
INRIA - projet Pastis | We will be restoring normality
BP 93 | just as soon as we are sure
06902 Sophia Antipolis Cedex | what is normal anyway.
France | Thank you. "
Phone #93 65 78 82 |
Fax #93 65 76 43 |
Email: se...@sophia.inria.fr | The Hitch-Hiker's Guide to the Galaxy
-----------------------------------------------------------------------
: What's the simplest way to transform a float to an int in tcl ?
: I've thought of :
: scan $float %d int
: but there sure must be a straighter way...
From the Tcl 7.0 "expr" manual page ...
Tcl also implements the |
following functions for conversion between integers and |
floating-point numbers: |
int(arg)
If arg is an integer value, returns arg, otherwise con- |
verts arg to integer by truncation and returns the con- |
verted value. |
round(arg)
If arg is an integer value, returns arg, otherwise con- |
verts arg to integer by rounding and returns the con- |
verted value. |
So you can use "int" or "round" depending on if you want the
real-value truncated or rounded.
set int [expr int($float)]
set int [expr round($float)]
--ga