X
HOME HTML CSS JAVASCRIPT SQL PHP JQUERY ANGULAR BOOTSTRAP 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 »

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

Your suggestion:

Close [X]

Thank You For Helping Us!

Your message has been sent to W3Schools.

Close [X]
Search w3schools.com:

WEB HOSTING

UK Reseller Hosting

WEB BUILDING

Download XML Editor FREE Website BUILDER Free HTML5 Templates

SHARE THIS PAGE

facebook