user1134991
user1134991

Reputation: 3103

How can one tell if a variable value is a number in TCL?

I want to check if an input is a valid number or not in Tcl. I.e.:
1.2.0 is not.
1.20 is.
1e-9 is
-00.61 is.
1.91e-a0 is not.
I could not find a good answer on the web.

Upvotes: 2

Views: 9745

Answers (1)

Peter Lewerin
Peter Lewerin

Reputation: 13282

string is double $myNum 

Returns 1 if it's a valid number, otherwise 0. Note that the empty string is considered a valid number unless you give the -strict option:

string is double -strict $myNum 

Documentation: string

Upvotes: 8

Related Questions