Ruby-like Question: Make this function shorter (ActionScript 3)

前端 未结 9 1191
春和景丽
春和景丽 2021-01-14 01:38

I just wrote this incredibly verbose code to turn numbers like 2 into 02. Can you make this function shorter, please (maintaning the functionality)?

9条回答
  •  深忆病人
    2021-01-14 01:48

    private function leadingZeros(value:int, numDigits:int):String
    {
                return String(new Array(numDigits + 1).join("0") + String(value)).substr(-numDigits, numDigits);
    }
    

提交回复
热议问题