Performance-wise, I prefer using a String constant and substr, like this:
package {
public class Helper {
private static const _ZEROS:String = "0000000000000000000000000000000000000000"; // 40 zeros, shorten/expand as you wish
/*
* f: positive integer value
* z: maximum number of leading zeros of the numeric part (sign takes one extra digit)
*/
public static function uint_Zeropadded(f:uint, z:int = 0):String {
var result:String = f.toString();
while (result.length < z)
result = _ZEROS.substr(0, z - result.length) + result;
return result;
}
}
}
The String constant has very little footstamp compared to the performance draw-backs of extending the string one by one digit numerous times. In most cases (up to 40 zeros in this example) number of instructions is the same for all calls.