Page History: ZPad$() - pad a number with leading zeroes
Compare Page Revisions
Page Revision: 2018/12/14 13:10
Some time it is nice to have leading zeroes on a number. MMBasic helpfully removes these for you which means to have them, the number must be returned as a string.
This tiddly Function does just that, it returns the integer value x, padded with y leading zeroes as a string. The same functionality can be produced with STR$() but is more involved
Syntax:
=ZPad$(number,howmanyzeroes)
Example:
Print ZPad$(7,3)' returns "007"
Code:
Function ZPad$(x As integer,y As integer)
'adds y leading zeroes to X
ZPad$=Right$(String$(y,"0")+Str$(x),y)
End Function