Created
March 29, 2011 08:14
-
-
Save think49/891983 to your computer and use it in GitHub Desktop.
to-zero-padding.js : 数値をゼロパディングされた数値文字列に変換する
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
/** | |
* to-zero-padding.js | |
* The Number value is changed to the numerical string value of zero padding. | |
* | |
* @version 1.1.1 | |
* @author think49 | |
* @url https://gist.github.com/891983 | |
* @license http://www.opensource.org/licenses/mit-license.php (The MIT License) | |
*/ | |
'use strict'; | |
var toZeroPadding = (function (Number, isNaN, Array) { | |
'use strict'; | |
function toZeroPadding (number, limit) { | |
number = Number(number); | |
if (isNaN(number)) { | |
return null; | |
} | |
return (Array(limit).join('0') + number).slice(-limit); | |
} | |
return toZeroPadding; | |
})(Number, isNaN, Array); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
コードサンプル