# Convert sting to integer

Guys
I’m looking at creating an app to turn on a switch at a wind level
e.g.

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?

Andy

.toInteger()

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.

2 Likes

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

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

Ok.

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)

}
``````

Andy

1 Like

Perfect.

Actual answers are so much better than guesses

1 Like

Hey!
you got me in the right direction

Andy

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)

3 Likes