[ Web Proxy ]
URL:
Viewing: https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Global_Objects/Number/toString [Back]  [Original]

Number.prototype.toString() - JavaScript | MDN

MDN Web Docs

View in English Always switch to English

Number.prototype.toString()

Baseline

20157

toString() Number

function hexColor(c) {
  if (c < 256) {
    return Math.abs(c).toString(16);
  }
  return 0;
}

console.log(hexColor(233));
// : "e9"

console.log(hexColor("11"));
// : "b"

js
toString()
toString(radix)

radix

2 36 10

10 1021 10-6

RangeError

radix 2 36

TypeError

Number

Number Object toString() Object.prototype.toString() Number toString

10 9 16 16a f

numObj 2 - 2 2

0 -0 "0" Infinity "Infinity" NaN "NaN"

. 10 1021 10-6

js
console.log((10 ** 21.5).toString()); // "3.1622776601683794e+21"
console.log((10 ** 21.5).toString(8)); // "526665530627250154000000"

2 toString() toString() 0

js
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()

js
Number.prototype.toString = () => "Overridden";
console.log(`${1}`); // "1"
console.log(`${new Number(1)}`); // "Overridden"

toString

js
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()

js
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