THE WORLD'S LARGEST WEB DEVELOPER SITE

JavaScript Number toString() Method

JavaScript Number Reference JavaScript Number Reference

Example

Convert a number to a string:

var num = 15;
var n = num.toString();

The result of n will be:

15

Try it yourself »

More "Try it Yourself" examples below.


Definition and Usage

The toString() method converts a number to a string.


Browser Support

Method
toString() Yes Yes Yes Yes Yes

Syntax

number.toString(radix)

Parameter Values

Parameter Description
radix Optional. Which base to use for representing a numeric value. Must be an integer between 2 and 36.
  • 2 - The number will show as a binary value
  • 8 - The number will show as an octal value
  • 16 - The number will show as an hexadecimal value

Technical Details

Return Value: A String, representing a number
JavaScript Version: 1.1

Examples

More Examples

Example

Convert a number to a string, using different bases:

var num = 15;
var a = num.toString();
var b = num.toString(2);
var c = num.toString(8);
var d = num.toString(16);

The result of a,b,c, and d will be:


Try it yourself »

JavaScript Number Reference JavaScript Number Reference

COLOR PICKER

colorpicker

SHARE THIS PAGE






Search w3schools.com:

Translate w3schools.com: