Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What would you use to zero pad a number in Flex/AS3?

Duplicate of this one.

What would you use to pad zeroes to the left of a number in Flex/AS3?

Is there an equivalent to printf or NumberFormat that does this?

I'm looking for the nicest implementation of this or something similar:

public function zeroPad(number:int, width:int):String {
    // number = 46, width = 4 would return "0046"
}
like image 852
lpfavreau Avatar asked Mar 20 '09 15:03

lpfavreau


1 Answers

public function zeroPad(number:int, width:int):String {
   var ret:String = ""+number;
   while( ret.length < width )
       ret="0" + ret;
   return ret;
}
like image 54
Phil Avatar answered Sep 24 '22 10:09

Phil