JS: Number.prototype.toString

By Xah Lee. Date: .

Convert a number to string.

radix is the base, defaults to 10.

// number to string
console.log(
    (30).toString() === "30"
); // true

Number to string, with radix:

To Binary

// int to binary string

console.log(
    (3).toString(2) === "11"
); // true

console.log(
    (16).toString(2) === "10000"
); // true

To Hex

// to hex

console.log(
    (15).toString(16) === "f"
); // true

console.log(
    (200).toString(16) === "c8"
); // true

Reference

ECMAScript® 2016 Language Specification#sec-number.prototype.tostring

Number Topic

  1. JS: Format Number
  2. JS: String to Number
  3. JS: Number Object
  4. JS: Number Constructor
  5. JS: Number.prototype
Liket it? Put $5 at patreon.

Or, Buy JavaScript in Depth

If you have a question, put $5 at patreon and message me.

Web Dev Tutorials

  1. HTML
  2. Visual CSS
  3. JS in Depth
  4. JS Reference
  5. DOM
  6. SVG
  7. Web Dev Blog