前端:
function PrefixInteger(num) {
return (num / Math.pow(10, 2)).toFixed(2).substr(2);
}
改进
function PrefixInteger(num, length) {
return ( "0000000000000000" + num ).substr( -length );
}
进一步改进
function PrefixInteger(num, length) {
return (Array(length).join('0') + num).slice(-length);
}
C#后端:
string str='23';
str.PadLeft(4, '0'); //结果为为 '0023'
str.PadLeft(4, ' ') //补为空格 ' 23'