Favorites

JavaScript Number.prototype.toString() Method

☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee
Number.prototype.toString()
JavaScript Number Instance methodThis method is supported by all modern browsers.
Updated 28th November 2026

The toString() method converts a number to a string, optionally in another base such as binary (2) or hexadecimal (16).

Description

The toString() method returns the number as a string. With a radix, it converts to another base: 2 for binary, 8 for octal, 16 for hexadecimal and up to 36. To call it on a number literal, use two dots or parentheses: 5..toString() or (5).toString().

Without a radix, the result is the shortest string that uniquely identifies the number, so (0.1 + 0.2).toString() shows all the digits needed, "0.30000000000000004". Very large and very small numbers use exponential notation.

Converting to binary or hexadecimal is common when working with colors, bit flags and character codes, and parseInt(str, radix) converts back. For human-readable formatting with separators and fixed decimals, use toLocaleString() or toFixed() instead.

Syntax

number.toString()
number.toString(radix)

Parameters

  • radixOptional. The base to use, from 2 to 36. Defaults to 10.

Return Value

A string representing the number in the given base.

Exceptions

  • RangeErrorThrown if the radix is outside 2 to 36.

Example

console.log((255).toString());
console.log((255).toString(16));
console.log((5).toString(2));
console.log(parseInt('ff', 16));

Browser Support

The following information will show you the current browser support for the Number.prototype.toString() method. Hover over a browser icon to see the version that first introduced support for this method.

This method is supported by all modern browsers.

Desktop

Chrome
Edge
Firefox
Opera
Safari

Tablets & Mobile

Chrome Android
Firefox Android
Opera Android
Safari iOS
Samsung Internet
Android WebView
-
Supported Unknown Not supported
☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee