O'Reilly logo

jQuery and JavaScript Phrasebook by Brad Dayley

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Converting Numbers to Strings

var n=16; var a = n.toString();  //a = 16 var b = n.toString(16); //b = 10

To convert a number to a string in JavaScript, create a variable with the numerical value if you don’t already have one and then call .toString(radix) on the number. The optional radix parameter specifies the base to use when converting the number. You can specify base 2 up to base 36.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required