Originally posted by: SystemAdmin
Howdy,
is there a neat way to convert a string to an integer (or float).
The main job will be to decide if the string corresponds
to an integer. There is the parseInt() function that returns
NaN in case that the string does not represent a valid integer.
But it is not obvious how this can be checked
execute
{ s =
"123" t =
"H235" writeln( s ,
"-->",parseInt(s)); writeln( t ,
"-->",parseInt(t));
if(parseInt(t) == NaN) writeln(
"NO Int")
}
yield to
123-->123 H235-->NaN
which is cossistent with the doc.
The NaN value is contagious, and a numeric operation involving NaN always returns NaN. A comparison operation involving NaN always returns
false — even the NaN == NaN comparison.
A construction like
if(!(parseInt(t) < 0 || parseInt(t) >= 0)) writeln(
"NO Int")
works - but it looks weird to me. There must be easier ways to do so.,
Any ideas or hints?
Regards
Norbert
#DecisionOptimization#OPLusingCPLEXOptimizer