Why is the above so difficult???
state.myInt=Integer.parseInt(myStr,16) // Exception error
state.myInt=myStr.toInteger() // Same
state.myInt=myStr as Integer // Dont think this even compiles.
Tried a whole bunch more and none work. Surely, I must be missing something as I cant believe such conversion is not possible.
Your string isn’t an integer (whole number). I think you would have to parse it into a double or float first, then round and finally convert that to an integer. If you parse to a double or float, then convert to an integer without rounding, it will just throw away everything after the decimal.
I despise type conversions!
That did the trick
def dDist = Math.round(Double.parseDouble(dist))
state.distance = dDist.toInteger()