+ 3

how to convert string to number?

Javascript I'm trying to use two numbers from the user input, (e.g. when I try to add input1+input2+123 ) input2 is added to 123 and input1 is just joined (58+2+123 results to 58125)

4th Apr 2018, 11:28 PM
Lumas Mulo
Lumas Mulo - avatar
4 Réponses
+ 3
Im assuming in Java. Integer.parseInt(string); Float.parseFloat(string); Double.parseDouble(string); Example: // inside main method String str = "42"; int num = Integer.parseInt(str);
4th Apr 2018, 11:34 PM
TurtleShell
TurtleShell - avatar
+ 2
The language is Javascript in html. (Thanks for your response)
4th Apr 2018, 11:39 PM
Lumas Mulo
Lumas Mulo - avatar
+ 2
There are parseInt() and parseFloat() functions: var str = "42"; var num = parseInt(str);
4th Apr 2018, 11:44 PM
TurtleShell
TurtleShell - avatar
0
Which programming language?
4th Apr 2018, 11:33 PM
Emma