From: S-Y. Chen on 10 Mar 2010 13:20 Dear All, I am having a headache about checking if a variable is a number (floating, double, and integer. Anything that is a numerical value). If I use if { [string is alnum "$_var1"] != 1} The strings like " " or " " (all blanks) will pass the test, giving So, is there a simple command to check if a variable is a numerical number ? And, is there also a simple command to check of a string is empty, or just full of blanks ? Thanks for the help in advance. regards S-Y. Chen
From: Don Porter on 10 Mar 2010 13:26 S-Y. Chen wrote: > So, is there a simple command to check if a variable is a numerical > number ? [string is double -strict $var] -- | Don Porter Mathematical and Computational Sciences Division | | donald.porter(a)nist.gov Information Technology Laboratory | | http://math.nist.gov/~DPorter/ NIST | |______________________________________________________________________|
From: Prof Craver on 10 Mar 2010 13:33 On Mar 10, 1:20 pm, "S-Y. Chen" <shenyeh_c...(a)hotmail.com> wrote: > Dear All, > > I am having a headache about checking if a variable is a number > (floating, double, and integer. Anything that is a numerical value). Hi, You can try something like if {[scan $myinput "%f%c" number stopper]==1} {bleh} If $myinput is a number, scan should output 1; if it is whitespace it should output -1; if it is nonnumerical garbage it should output 0; and if it is garbage that begins with numerical characters, e.g. -123abc, it should output 2. --X
|
Pages: 1 Prev: bidirectional pipe question Next: Call For Ideas - GSoC/Tcl 2010 |