I just wrote this incredibly verbose code to turn numbers like 2 into 02. Can you make this function shorter, please (maintaning the functionality)?
How about this:
public static function format(n:int, len:int):String {
var v:String = n.toString();
return (v.length >= len) ? v : String(Math.pow(10, len) + n).substr(1);
}
There is not built-in function to do this btw. If you need decent padding functions, take a look at the StringUtils in Apache Commons Lang.