Convert sting to integer

I’m looking at creating an app to turn on a switch at a wind level

if(wind > number){
do something

The problem I have is that the WU driver outputs the figures as strings.
Is there an easy way to convert this to an integer?



mywind.value = wind.toInteger()

I feel like I must be missing something in the question because MY answer came too easily. So easy, my answer has to be wrong. :frowning:


this is my mini handler:

def wind_mphHandler(evt){ 
    def event6 = evt.value
    evt6.value = event6.toInteger()     (line 187)
    def call6 = 'Wind Speed'
    LOGDEBUG("Wind =  $evt6.value")
    actionNow(call6, evt6.value)


but it’s returning this error:

app:2722018-04-23 17:05:21.485:error For input string: “1.0” on line 187

1.0 isn’t an integer in the sense it’s got a decimal point. I’d imagine the tointeger() routine scans the string and sees the decimal point and gives up.

One wild.ass.guess is all I can do per hour :smiley:

Are the range of values actually integers expressed as floating? How many significant places? Can you adjust/truncate the string before invoking toInteger() ?

The answer came from @bobbyD

def evt6 = event6.toDouble() this works!

so my handler now look like this:

def wind_mphHandler(evt){ 
def event6 = evt.value
    def evt6 = event6.toDouble()
    def call6 = 'Wind Speed'
    LOGDEBUG("Wind =  $evt6")
    actionNow(call6, evt6)



1 Like


Actual answers are so much better than guesses :smiley:

1 Like

you got me in the right direction :slight_smile:


float vs. double: float represents 32-bit floating point numbers (E.G. 12.34) vs. double, which represents 64-bit floating point numbers (longer decimals E.G. 12.3456565)