Skip to content

Instantly share code, notes, and snippets.

@yuezk
Last active August 29, 2015 14:07
Show Gist options
  • Save yuezk/0f8ccbe45d612263c4f2 to your computer and use it in GitHub Desktop.
Save yuezk/0f8ccbe45d612263c4f2 to your computer and use it in GitHub Desktop.
在指定的数字前补0
/**
* @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