Forum Discussion

bdre's avatar
bdre
Occasional Contributor
6 years ago
Solved

zero pad string in groovy script

in my Groovy script I want to format an integer as a zero padded string.  Something like:

 

 

def row = 27
log.info "zero padded = " + Format("%04i", row)

can it be done?

  • Hey, this can be done quite simply:

     

     

    def row = 27
    def paddedRow = String.format("%010d", row)

    log.info paddedRow

     

    By "%010d" you specify how many digits do you want your number to have.

     

    Lucian.

1 Reply

  • Lucian's avatar
    Lucian
    Community Hero

    Hey, this can be done quite simply:

     

     

    def row = 27
    def paddedRow = String.format("%010d", row)

    log.info paddedRow

     

    By "%010d" you specify how many digits do you want your number to have.

     

    Lucian.