如何检查数学结果是否正确

时间:2017-01-25 17:37:58

标签: tcl

如何捕获计算表达式但仍然继续处理直到完成并低于脚本;

set vars {33 53 65t 43 word 55 d}
foreach varList $vars {
 if {[expr {$varList / $varList}] == 1} {    ;#I am stuck maths here if its not numerics string
   set mathVar $varList
 } else {
   set mathVar "Invalid"
 }
}

谢谢!

1 个答案:

答案 0 :(得分:1)

您需要string is integer

foreach var $vars {
    if {[string is integer -strict $var]} {
        set mathvar $var
    } else {
        puts "not an integer: $var"
        set mathvar 0     ;# or some default value
    }
}