It is possible to get frustrated when you are coding in JavaScript and are trying to do some arithmetic calculations in the course of your JavaScript programming.
Here, it is possible to find out that 1000 + 1 is equal to 10001 and 10001 + 10 equals 1000110.
This is where you find out that all that you learnt in the school is wrong. It is also when you feel just a wee bit superior to the computer, because you know that sometimes, it has to be specifically instructed on what to do, how to interpret and calculate.
In JavaScript, there is one function that we can use to tell the computer that we are dealing with numbers and not strings. We use the function Number("numberInStringForm") to convert a number inside a string into a number.
This happens most of the time when numbers are part of a web form/report where all content is text. Based on the position of the text, based on the id or class name that we identify them with, we have to extract the content, which will be by default in "string form".
This is where we use the Number() function to convert them into number form again. After this Number() function is used, the number in the string variable is converted into a number, upon which we can then use the arithmetical operators (+-*/^ etc) to get the numerical answers.
Usage: stringToNumber =Number("12345")
Here, it is possible to find out that 1000 + 1 is equal to 10001 and 10001 + 10 equals 1000110.
This is where you find out that all that you learnt in the school is wrong. It is also when you feel just a wee bit superior to the computer, because you know that sometimes, it has to be specifically instructed on what to do, how to interpret and calculate.
In JavaScript, there is one function that we can use to tell the computer that we are dealing with numbers and not strings. We use the function Number("numberInStringForm") to convert a number inside a string into a number.
This happens most of the time when numbers are part of a web form/report where all content is text. Based on the position of the text, based on the id or class name that we identify them with, we have to extract the content, which will be by default in "string form".
This is where we use the Number() function to convert them into number form again. After this Number() function is used, the number in the string variable is converted into a number, upon which we can then use the arithmetical operators (+-*/^ etc) to get the numerical answers.
Usage: stringToNumber =Number("12345")