Tcl:Very strange output!!

Hi,

I using tcl script to perform certain conditions. Part of the results should have average . I couldn't figure out what 's the cause as the result of the average is Zero.
Example of the case????

#!/usr/bin/tclsh

set counter 500
set total 1000

puts  "Total num: $total \n"
puts  "Total counter : $counter \n"

set average [expr { ($counter / $total ) *100} ]
puts "average: $average"


the result is Zero??? any idea why????:rolleyes:

Integer arithmetic truncates, and you divide first. You want:

set average [expr { ( $counter * 100 ) / $total } ]

Thank you it works

I thought it's like any other language.

Thanks..

You thought float, not int.