How do I round say 1.23 up/down to 2 decimal places? I am currently
(ab)using [format].
Thanks
Evilson
> How do I round say 1.23 up/down to 2 decimal places? I am currently
> (ab)using [format].
Sounds like the right choice.
--
Donald Arseneau as...@triumf.ca
Using [format] is completly correct way, but if you prefer to avoid it
for some reason, there is other way:
set precision 2
set roundedValue [expr { double(round($value * pow(10,$precision))) /
pow(10,$precision) }]
Regards,
Googie
Thanks Donald and Googie ... least of all for figuring out what I
meant. My example should have been 1.234 :P
Yes [format] works fine on my machine but I was just wondering about
whether it would behave the same on other machines and whether that
was the correct way to do it. Sounds like it is. (IIRC, C's <stdio.h>
printf's behaviour is undefined here. But this is Tcl of course ...
and my C is rusty.)
Thanks again.
Evilson