[Actionscript] Add Leading Zero


以前只是很簡單的pad 1個0在前面,沒有想過寫一個utility class。

所以,既然有人教,當然要記住la

1
2
3
4
5
6
7
8
function addZero(n:int, numZeros:int = 1):String {
var str:String = n + “”;
while (str.length<numZeros+1)
{
str = “0+ str;
}
return str;
}

Source: http://shang-liang.com/blog/algorithm-for-adding-leading-zeros/

Share

  1. No comments yet.
(will not be published)

Anti-Spam Protection by WP-SpamFree