| [ Web Proxy ] |
| Viewing: https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Global_Objects/Number/toString | [Back] [Original] |
Get to know MDN better
function hexColor(c) {
if (c < 256) {
return Math.abs(c).toString(16);
}
return 0;
}
console.log(hexColor(233));
// : "e9"
console.log(hexColor("11"));
// : "b"
toString()
toString(radix)
radix 2 36 10
10 1021 10-6
RangeErrorradix 2 36
TypeErrorNumber Object toString() Object.prototype.toString() Number toString
10 9 16 16a f
numObj 2 - 2 2
0 -0 "0" Infinity "Infinity" NaN "NaN"
console.log((10 ** 21.5).toString()); // "3.1622776601683794e+21"
console.log((10 ** 21.5).toString(8)); // "526665530627250154000000"
console.log((1000000000000000128).toString()); // "1000000000000000100"
console.log(1000000000000000100 === 1000000000000000128); // true
Number.prototype.toFixed() Number.prototype.toPrecision() toString()
toString() this Number this TypeError
Number [Symbol.toPrimitive]() Number JavaScript toString() toString() toString()
Number.prototype.toString = () => "Overridden";
console.log(`${1}`); // "1"
console.log(`${new Number(1)}`); // "Overridden"
const count = 10;
console.log(count.toString()); // "10"
console.log((17).toString()); // "17"
console.log((17.2).toString()); // "17.2"
const x = 6;
console.log(x.toString(2)); // "110"
console.log((254).toString(16)); // "fe"
console.log((-10).toString(2)); // "-1010"
console.log((-0xff).toString(2)); // "-11111111"
10 parseInt() toString()
const hex = "CAFEBABE";
const bin = parseInt(hex, 16).toString(2); // "11001010111111101011101010111110"
Number.MAX_SAFE_INTEGER BigInt BigInt 0b, 0o, 0x 2 8 10 16
| ECMAScript 2027 LanguageSpecification # sec-number.prototype.tostring |
| Web Proxy Viewer | New URL | Original Page |