Monday, 5 August 2013

Padding a number with zeros

The result must be a text/string field since you can't have real numbers with preceding zeros.  Placed here so I don't rediscover it for the 3rd time.  The number "a" is converted to a string ("b") then padded so that the final string length is 8, padded with 0's at the beginning.

>>> a = 17.98
>>> b = str(a).zfill(8)
>>> b
'00017.98'
>>>

No comments:

Post a Comment