+ 5
How do I turn a string to a number in JavaScript?
I know one language uses tostring_i or something. Is there something like that in JavaScript? I'm trying to use JS to make something that uses a math formula to partition a segment. https://code.sololearn.com/WzPcAhT6x0X2/?ref=app
4 Answers
+ 5
Use the value attribute to get the value of the input element.
There are many ways to convert string to number in JavaScript. Some examples:
var str = "123.42"
parseInt(str) //123
parseFloat(str) //123.42
Number(str) //123.42
+str //123.42
Soapyguy [A Bit Inactive with School] You are welcomeđ. By the way the last one is called unary plus, in case you want to do some research.
+ 4
I think I'll just try to make something where the user has to input the values, something still isn't working
+ 4
"Use the value attribute to get the value of the input element."
I think I was not clear enough when i said that. What I meant:
var x = document.getElement....(input) // x is the HTMLInput element
var y = x.value // y is the value entered by user
+ 3
Ok thanks, this should end up being very helpful