Skip to content

Instantly share code, notes, and snippets.

@itzarty
Created July 11, 2022 12:37
Show Gist options
  • Save itzarty/96e7439a63ac3800335ecb72a63d255c to your computer and use it in GitHub Desktop.
Save itzarty/96e7439a63ac3800335ecb72a63d255c to your computer and use it in GitHub Desktop.
Number.prototype.placeFormat = function( places, limited ) {
if( !places || places < 2 ) places = 2;
if( !limited ) limited = true;
var number = this.toString( );
if( number.length > places && limited == true ) return number.slice( 0, places - number.length );
if( number.length < places ) {
while( number.length != places ) {
number = "0" + number;
}
return number;
}
if( number.length == places ) return number;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment