X
HOME HTML CSS JAVASCRIPT SQL PHP JQUERY XML ASP.NET MORE...
REFERENCES | EXAMPLES | FORUM | ABOUT

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 »


Definition and Usage

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


Browser Support

Internet Explorer Firefox Opera Google Chrome Safari

The toString() method is supported in all major browsers.


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

Return Value

Type Description
String The number as a string

Technical Details

JavaScript Version: 1.1


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

Your suggestion:

Close [X]

Thank You For Helping Us!

Your message has been sent to W3Schools.

Close [X]
Search w3schools.com:

WEB BUILDING

Download XML Editor FREE Website BUILDER Free HTML5 Templates FREE Website Templates Free HTML Templates

SHARE THIS PAGE

facebook