代码如下:
function GetFullNumber(num, length) {
var maxNumber = 1;
for (var i = 1; i < length; i++) {maxNumber *= 10;}
maxNumber = maxNumber.toString();
num = num.toString();
var startLength = num.length;
if (num.indexOf(".") >= 0) {startLength = num.substring(0, num.indexOf(".")).length;
}
for (var i = startLength; i < maxNumber.length; i++) {num = "0" + num;}
return num;
}
比方 GetFullNumber(9, 2) 返回 “09”,办法反对小数。