JS: Number.prototype.toString

By Xah Lee. Date: . Last updated: .
(number).toString()
Convert a number to string.
(30).toString() === "30"
(number).toString(radix)
Use base radix.
// decimal number to binary string
console.log((3).toString(2) === "11");
console.log((16).toString(2) === "10000");

// works for decimal number too
console.log((2.5).toString(2) === "10.1");
// int to hexadecimal
console.log((15).toString(16) === "f");
console.log((200).toString(16) === "c8");

// works for decimal number too
console.log((15.5).toString(16) === "f.8");
BUY ΣJS JavaScript in Depth

JavaScript, Convert Decimal, Hexadecimal, Binary