Last active
August 29, 2015 14:07
-
-
Save yuezk/0f8ccbe45d612263c4f2 to your computer and use it in GitHub Desktop.
在指定的数字前补0
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @description 在指定的数字前补0 | |
* | |
* @num 要补0的数字 | |
* @length 补0之后的总长度 | |
* | |
* @return 补0之后的结果 | |
*/ | |
function padding(num, length) { | |
return new Array(Math.max((length || 0) - String(num).length + 1, 0)).join(0) + num; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment