You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
11 lines
361 B
JavaScript
11 lines
361 B
JavaScript
function zeroFill(number, width, osign) {
|
|
var num = '' + Math.abs(number),
|
|
zerosw = width - num.length,
|
|
sign = number >= 0;
|
|
return (sign ? (osign ? '+' : '') : '-') +
|
|
Math.pow(10, Math.max(0, zerosw)).toString().substr(1) + num;
|
|
}
|
|
|
|
console.log(zeroFill(120, 5, '-'));
|
|
|
|
console.log(zeroFill(29, 4));
|