+ 1

Convert Integer to String

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

26th Jun 2017, 9:57 PM
Javier I. Rivera R.
Javier I. Rivera R. - avatar
6 Antworten
+ 4
Integer to string: var num = 15; var n = num.toString(); String to integer: var string = "15"; var n = parseInt(string);
26th Jun 2017, 10:01 PM
G.Kasperski
G.Kasperski - avatar
+ 5
Int to string str = 10+"" String to int num = "10"*1
26th Jun 2017, 10:12 PM
CalviŇ▓
CalviŇ▓ - avatar
+ 2
Why one is a method (toString) and another is a function (parceInt) ?
26th Jun 2017, 10:39 PM
The Gocho┬┤s
The Gocho┬┤s - avatar
+ 2
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
27th Jun 2017, 6:31 AM
Elijah Bobzom
Elijah Bobzom - avatar
+ 1
The toString() method belongs to the Object class which Number inherits from, as do all JavaScript classes.
26th Jun 2017, 10:47 PM
ChaoticDawg
ChaoticDawg - avatar