Skip to content

Instantly share code, notes, and snippets.

@hrstt
Created September 5, 2011 06:34
Show Gist options
  • Save hrstt/1194242 to your computer and use it in GitHub Desktop.
Save hrstt/1194242 to your computer and use it in GitHub Desktop.
javascript: 数字の桁揃え
// repeat character
String.prototype.repeat = function(num) {
return new Array(num + 1).join(this);
}
// convert strings and filling zero
String.prototype.decimalf = function(num) {
if (isNaN(this) || isNaN(num) || num < 0){ return this;};
ary = this.split(".");
if(num == 0) { return ary[0]; };
ary[1] = (((ary.length>2)? ary[1] : "") + "0".repeat(num)).substring(0,num);
return ary.slice(0,2).join(".");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment