| [ Web Proxy ] |
| Viewing: https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Global_Objects/parseInt | [Back] [Original] |
Get to know MDN better
console.log(parseInt("123"));
// 123 (default base-10)
console.log(parseInt("123", 10));
// 123 (explicitly specify base-10)
console.log(parseInt(" 123 "));
// 123 (whitespace is ignored)
console.log(parseInt("077"));
// 77 (leading zeros are ignored)
console.log(parseInt("1.9"));
// 1 (decimal part is truncated)
console.log(parseInt("ff", 16));
// 255 (lower-case hexadecimal)
console.log(parseInt("0xFF", 16));
// 255 (upper-case hexadecimal with "0x" prefix)
console.log(parseInt("xyz"));
// NaN (input can't be converted to an integer)
parseInt(string)
parseInt(string, radix)
string NaN
radix 32 2 36 :
JavaScript parseInt() parseFloat() parseInt("42") parseFloat("42") 42
parseInt 1 NaN
NaN 1 radix (radix 10 10 8 8 16 16 )
radix 0NaNInfinity undefined NaN JavaScript
string +/- 0x 0X X radix 16 16 string 10 10 16 parseInt() (+/-) 0x 0X
[2, 36] parseInt NaN
10 9 16 16 A F
parseInt 2 + -
parseInt radix parseInt("2", 2) 2 2 NaN 1e3 parseFloat() 1000 parseInt("1e3", 10) 1 e 10 .
parseInt NaN
NaN Number.isNaN parseInt NaN NaN NaN
e 6.022E23 6.022 10^23 parseInt parseInt Math.trunc()
15
parseInt("0xF", 16);
parseInt("F", 16);
parseInt("17", 8);
parseInt("015", 10);
parseInt("15,123", 10);
parseInt("FXX123", 16);
parseInt("1111", 2);
parseInt("15 * 3", 10);
parseInt("15e2", 10);
parseInt("15px", 10);
parseInt("12", 13);
NaN
parseInt("Hello", 8); //
parseInt("546", 2); // 2 0 1
-15
parseInt("-F", 16);
parseInt("-0F", 16);
parseInt("-0XF", 16);
parseInt("-17", 8);
parseInt("-15", 10);
parseInt("-1111", 2);
parseInt("-15e1", 10);
parseInt("-12", 13);
224
parseInt("0e0", 16);
parseInt() BigInt n
parseInt("900719925474099267n");
// 900719925474099300
n BigInt()
BigInt("900719925474099267");
// 900719925474099267n
parseInt("123_456"); // 123
parseInt() 36
parseInt(null, 36); // 1112745: "null" 36 1112745
parseInt(undefined, 36); // 86464843759093: "undefined" 36 86464843759093
parseInt() Math.trunc()
parseInt(15.99, 10); // 15
parseInt(-15.1, 10); // -15
("15.99", "-15.1") parseInt() 1e+21 1e-7 ("1.5e+22", "1.51e-8") parseInt() e parseInt() 1
parseInt(4.7 * 1e22, 10); // 4
parseInt(0.00000000000434, 10); // 4
parseInt(0.0000001, 10); // 1
parseInt(0.000000123, 10); // 1
parseInt(1e-7, 10); // 1
parseInt(1000000000000000000000, 10); // 1
parseInt(123000000000000000000000, 10); // 1
parseInt(1e21, 10); // 1
| ECMAScript 2027 LanguageSpecification # sec-parseint-string-radix |
| Web Proxy Viewer | New URL | Original Page |