Created
May 11, 2009 15:58
-
-
Save furf/110034 to your computer and use it in GitHub Desktop.
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
/** | |
* Adds a leading zero to numbers less than 10 | |
* | |
* @param {Number|String} val Numeric value | |
* @param {Number} len (optional, default = 2) String length | |
* @return {String} Modified value | |
*/ | |
var addLeadingZero = function(val /*, len */) { | |
var str = val.toString(); | |
var len = arguments[1] || 2; | |
while (str.length < len) { | |
str = '0' + str; | |
} | |
return str; | |
}; | |
var addLeadingZeroes = addLeadingZero; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment