English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
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.
number.toString(radix)
var num = 14; var str = num.toString();Test and see‹/›
All browsers fully support the toString() method:
Method | |||||
toString() | is | is | is | is | is |
Parameter | Description |
---|---|
radix | (Optional)between2to36An integer between, specify the radix used to represent the number:
|
Return value: | String representing a number |
---|---|
Exception cases: | If the toString() method is givenradixless than2or greater36then throws a RangeError |
JavaScript Version: | ECMAScript 1 |
Convert a decimal number to a binary number:
var num = 10; num.toString(2);// 1010Test and see‹/›
Convert a decimal number to a hexadecimal number:
var num = 10; num.toString(16);// aTest and see‹/›