|
|
Check if a variable is a number
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
|
|
0
|
|
|
|
Reply
|
S
|
3/10/2010 6:20:27 PM |
|
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@nist.gov Information Technology Laboratory |
| http://math.nist.gov/~DPorter/ NIST |
|______________________________________________________________________|
|
|
0
|
|
|
|
Reply
|
Don
|
3/10/2010 6:26:25 PM
|
|
On Mar 10, 1:20=A0pm, "S-Y. Chen" <shenyeh_c...@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]=3D=3D1} {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
|
|
0
|
|
|
|
Reply
|
Prof
|
3/10/2010 6:33:45 PM
|
|
|
2 Replies
1206 Views
(page loaded in 0.058 seconds)
Similiar Articles: Check if a variable is a number - comp.lang.tclDear All, I am having a headache about checking if a variable is a number (floating, double, and integer. Anything that is a numerical value). ... check for variable existence, if not there put variable in. - comp ...Check if a variable is a number - comp.lang.tcl check for variable existence, if not there put variable in. - comp ... Check if ... call might be getting ... named ... Bitwise comparison of 2 numbers - comp.lang.awkCheck if a variable is a number - comp.lang.tcl Bitwise comparison of 2 numbers - comp.lang.awk... modify some old code so that it performs a bitwise "and" on two numbers. Checking to see if a value exists - comp.databases.filemaker ...Check if a variable is a number - comp.lang.tcl Anything that is a numerical value). If I use if { [string is alnum "$_var1 ... Undefined XLIB Name - comp.sys.hp48 So, it ... I have a isNumeric function to check a text field is numeric .. I ...... forms value as a float number. I understand that it should just simply be a change to the value of the numericExpression variable but Im ... joost@zeekat.nl> writes: > See ... how do I check for existance of env var in bash - comp.unix ...How do I check if an environment variable exists and f it is defined in a bash shell ... Undefined XLIB Name - comp.sys.hp48So, it is a > lot to check to see where a LIB call might be getting ... named variables) are converted into libraries, all of the variable names are replaced by numbers ... How to define a binary variable in matlab? - comp.soft-sys.matlab ...> > > Xu > > You can define x as a binary variable by using either x =3D true or x =3D= false. However, equations you presented in the post is not a clear descrpt= ion of ... [tempo] Convert variable from string to number - comp.emacs ...I'd like to convert (the value of) a variable inside a tempo template from a string to a number. This doesn't work: (tempo-define-template "whatsis" ... making a scalar - comp.soft-sys.matlab... and I am trying to make a variable a scalar not a variable. ... Speaking personally, when I see the i*h term in that ... How do I determine whether a text string is a number ... Check if variable is a number - The UNIX and Linux ForumsUNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !! Check if a variable is a number - perl - The UNIX and Linux ForumsThe POSIX example above only gives integers, not other real numbers... Here's an alternative that I think may execute more quickly than using a regular expression or ... 7/23/2012 6:23:02 AM
|
|
|
|
|
|
|
|
|