Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Hello i am a beginner to groovy i am cofused how to check whether the given input is a number or not i tried the following

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

Kindly help me how to use isNan in groovy.I googled it lot but didnt find any result . Thanks in advance

like image 225
shashank Avatar asked Nov 30 '22 03:11

shashank


1 Answers

Groovy's String::isNumber() to the rescue:

def a = "a"

assert !a.isNumber()

def b = "10.90"

assert b.isNumber()
assert b.toDouble() == 10.90
like image 120
Will Avatar answered Dec 04 '22 22:12

Will