10 examples of 'javascript format number 2 digits' in JavaScript

Every line of 'javascript format number 2 digits' 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
this disclaimer
99function format2Digits(num) {
100 return num < 10 ? '0' + num : num;
101}
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

4export function addDigits(num) {
5 let sum = 0;
6
7 for (let n of num.toString()) {
8 sum += +n;
9 if (sum >= 10) {
10 sum = sum - 9;
11 }
12 }
13
14 return sum;
15}
61function groupDigits(num) {
62 var ret = "";
63 while (num.length > 3) {
64 ret = "." + num.slice(num.length - 3) + ret;
65 num = num.substring(0, num.length - 3);
66 }
67 ret = num + ret;
68
69 return ret;
70}
240function twoDigitsFormat(num) {
241 return (num < 10) ? '0'+ num : num;
242}
107function twoDigits(n) {
108 return n < 10 ? '0' + n : '' + n;
109}
167function floatDigits(n) {
168 return (n = String(n)).slice(n.indexOf('.')).length - 1;
169}
37function padNumber(n, digits) {
38 var s = "" + n;
39 for (var i = 0; i < digits - s.length; i++) {
40 s = "0" + s;
41 }
42 return s;
43}
31function digits3(n) {
32 return n < 100 ? '0' + digits2(n) : n ;
33}
50export function formatDecimal8 (num, locale) {
51 return formatDecimal(num, locale, 0, 8)
52}
110function toHexDigit (number) {
111 const digits = '0123456789abcdef'
112 return digits.charAt(number >> 4) + digits.charAt(number & 0x0f)
113}

Related snippets