English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

JavaScript Number toString() Method

 JavaScript Number Object

toString()method is used to: return a string representation of the specified number.

method parses its first parameter and attempts to return the string representation of the specified radix (base).

for base greater than10letter, which represents numbers greater than9number. For example, for hexadecimal numbers (base of16Using a to F.

If the radix is not specified, the default preferred radix is assumed10.

Syntax:

number.toString(radix)
var num = 14;
var str = num.toString();
Test and see‹/›

Browser Compatibility

All browsers fully support the toString() method:

Method
toString()isisisisis

Parameter Value

ParameterDescription
radix(Optional)between2to36An integer between, specify the radix used to represent the number:
  • 2-The number will be displayed as a binary value

  • 8-The number will be displayed as an octal value

  • 16-The number will be displayed as a hexadecimal value

Technical Details

Return value:String representing a number
Exception cases:If the toString() method is givenradixless than2or greater36then throws a RangeError
JavaScript Version:ECMAScript 1

More Examples

Convert a decimal number to a binary number:

var num = 10;
num.toString(2);// 1010
Test and see‹/›

Convert a decimal number to a hexadecimal number:

var num = 10;
num.toString(16);// a
Test and see‹/›

 JavaScript Number Object