Created
September 5, 2011 06:34
-
-
Save hrstt/1194242 to your computer and use it in GitHub Desktop.
javascript: 数字の桁揃え
This file contains hidden or 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
// 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