Skip to content

Instantly share code, notes, and snippets.

@aderbas
Last active April 19, 2021 14:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aderbas/131c32cef214ece60726868de983f790 to your computer and use it in GitHub Desktop.
Save aderbas/131c32cef214ece60726868de983f790 to your computer and use it in GitHub Desktop.
Add zero left
/**
* Pad zero
* @param Number number
* @param Number size
* @return String
*/
const zeroLeft = (number,size) => {
var sign = Math.sign(number) === -1 ? '-' : '';
return sign + new Array(size).concat([Math.abs(number)]).join('0').slice(-size);
}
zeroLeft(25, 6) = 000025
zeroLeft(12023, 6) = 012023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment