groovyshell - How to check whether the input is a number or string by using isNan() in groovy -


hello beginner groovy cofused how check whether given input number or not tried following

def a= ' 12.571245error' if(a.isnan()==0) { println("not number") } else { println("number") } 

kindly me how use isnan in groovy.i googled lot didnt find result . in advance

you can try cast number , catch exception if not number

def a= ' 12.571245error'  try {     double     println "a number" }catch (e) {     println "a not number" } 

or

if(a instanceof number)     println "number" else     println "nan" 

although keep in mind, in second way of checking it, fail if a valid number in string "123". 123 number "123" not.


Comments

Popular posts from this blog

css - Which browser returns the correct result for getBoundingClientRect of an SVG element? -

gcc - Calling fftR4() in c from assembly -

Function that returns a formatted array in VBA -