Forum Discussion

Mason's avatar
Mason
Frequent Contributor
16 years ago

[RESOLVED] Converting property from String to Int

I'm sure there is something obvious I'm missing (haven't done much GroovyScripting) however I'm curious as to why this code does not produce an output of '20' assuming that #pageIncrement property == 10.

def nextIncrement = (context.expand('${#pageIncrement}'))
log.info(nextIncrement)
nextIncrement.toInteger()
nextIncrement = nextIncrement + 10
log.info(nextIncrement)

1 Reply

  • M_McDonald's avatar
    M_McDonald
    Super Contributor
    nextIncrement.toInteger() does not convert nextIncrement, it returns an Integer, so you have to assign to a new variable.

    def nextIncrementInt = nextIncrement.toInteger()
    nextIncrementInt += 10
    log.info nextIncrementInt