10 examples of 'javascript remove leading zeros' in JavaScript

Every line of 'javascript remove leading zeros' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
154function removeLeadingZeros(input, startIndex, endIndex) {
155 return input.slice(0, startIndex) + input.slice(endIndex);
156}
15function removeLeadingZeros (numeric) {
16 return numeric.replace(LeadingZeroRE, '$1')
17}
30function addZeros (block) {
31 if (block === '') {
32 return '0';
33 } else {
34 return block;
35 }
36}
148function removeTrailingZeros(value) {
149 value = value.toString();
150
151 if (value.indexOf('.') === -1) {
152 return value;
153 }
154 while ((value.slice(-1) === '0' || value.slice(-1) === '.') && value.indexOf('.') !== -1) {
155 value = value.substr(0, value.length - 1);
156 }
157 return value;
158}
4function addZeros(i, zeros) {
5 if (zeros === undefined) {
6 zeros = 3;
7 }
8 var s = i.toString();
9 while (s.length < zeros)
10 {
11 s = '0' + s;
12 }
13 return s;
14}
47function removeLeadingZero(num) {
48 var strNum = num.toString();
49 if (0 < num && num < 1 && strNum.charCodeAt(0) === 48) {
50 strNum = strNum.slice(1);
51 }
52 else if (-1 < num && num < 0 && strNum.charCodeAt(1) === 48) {
53 strNum = strNum.charAt(0) + strNum.slice(2);
54 }
55 return strNum;
56}
49function addZeros(value, len) {
50 value = "" + value;
51
52 if (value.length < len) {
53 for (var i=0; i<(len-value.length); i++)
54 value = "0" + value;
55 }
56
57 return value;
58};
6function addZeros(str, targetLength = 2) {
7 while (str.length < targetLength) {
8 str = `0${str}`
9 }
10
11 return str
12}
150function addLeadingZero(input, index) {
151 return input.slice(0, index) + '0' + input.slice(index);
152}
5function addZeros(n, l){
6 n = n.toString();
7 while(n.length < l){
8 n = '0' + n;
9 }
10 return n;
11}

Related snippets