Last active
April 19, 2021 14:02
-
-
Save aderbas/131c32cef214ece60726868de983f790 to your computer and use it in GitHub Desktop.
Add zero left
This file contains 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
/** | |
* 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