Convert Integer to String | Sololearn: Learn to code for FREE!


Convert Integer to String

How do I convert in Javascript a string to an integer and an integer to a string

6/26/2017 9:57:29 PM

Javier I. Rivera R.

6 Answers

New Answer


Integer to string: var num = 15; var n = num.toString(); String to integer: var string = "15"; var n = parseInt(string);


Int to string str = 10+"" String to int num = "10"*1


Javascript doesn't have an integer type, but a Number type.


Why one is a method (toString) and another is a function (parceInt) ?


string to integer use: Number(//your argument here); integer to string use: String(//your argument here); for the case of string to integer Number() will convert a number with quotes to a number without quotes (of type number) but if your argument is a float you have to use these: Math.ceil(argument);// to always round up to highest value. Math.floor(argument);// to always round down to lowest integer Math.round(argument);// to round up or down


The toString() method belongs to the Object class which Number inherits from, as do all JavaScript classes.