Adding leading zeros to a numeric value and converting it to a string

Hello I have a OPC tag value which can be 5 7 8 9 or 10 digit. I want to make them all 10 digit by adding whatever amount of 0 need to be added. Also need to store this data as it is with zeros in the beginnig as a 10 digit string. How can I do this value change script ?

Thanks

Assuming you want to pad the zeroes in front, here’s a few different ways.

strValue = '%010d' % value

strValue = '{:010d}'.format(value)

strValue = str(value).zfill(10)

The second one, I believe, is considered the preferred method for Python 2.7+, but a few options doesn’t hurt.

1 Like

Are you missing a single quote in that first option?

Yep. Thanks.

it works thanks Jordan