Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Division operator is not producing any results

Tags:

tcl

I ran into problem in TCL. I can add and multiply two integer variables. This works just fine:

set hdsuc [expr {$hdsuccess * $hdcount}]
set hdsuc [expr {$hdsuccess + $hdcount}]

But, for some reason, I am not able to divide them. Following does not work at all:

set hdsuc [expr {$hdsuccess / $hdcount}]

The above returns 0. Could there some issue with the settings?

like image 553
Micheal Avatar asked Nov 20 '25 03:11

Micheal


1 Answers

It's doing integer division. You need to convert one of the arguments to a double. e.g.:

 set hdsuc [expr {double($hdsuccess) / $hdcount}]
like image 59
thelazydeveloper Avatar answered Nov 21 '25 18:11

thelazydeveloper



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!