Reputation: 3103
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
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