subhaD

6 years agoContributor

# Groovy Script convert string to integer

latest = "123123123"
int number = latest.toInteger()
I am trying to convert this string to integer, tried various options from internet.
I always get "java.lang.NumberFormatException", but ...

- 6 years ago
Hi subhaD,

The number which you mentioned in original post is different from the number for which you are getting error.

So the solution for your problem is :

Int datatype can only handle "2147483647" in groovy if you pass "214748364

**8**" then it will give you the NumberFormatException ErrorYou can use Long dataType which can handle "9223372036854775807" but if you think at some point of time your number will be bigger than this then you must use BigInteger which can handle "9223372036854775807"

def latest = "4519021761189580" def number = latest.toLong() log.info number

Click "Accept as Solution" if my answer has helped, and remember to give "kudos" :)

Thanks and Regards,

Himanshu Tayal