over 8 years ago
Hello reader's in this tutorial we will convert string in a table to a numbers, for doing this we have to access the values in a HTML table and for processing we have to convert into numbers.
Using the Document Object Model (DOM) API we can Access the numbers and to convert the strings to number values we can use the global function parseInt:
Syntax:-
var rows = document.getElementById("table1").children[0].rows;
var numArray = new Array();
for (var i = 0; i < rows.length; i++) {
numArray[numArray.length] = parseInt(rows[i].cells[1].firstChild.data);
}
var rows = document.getElementById("table1").children[0].rows;
var numArray = new Array();
for (var i = 0; i < rows.length; i++) {
numArray[numArray.length] = parseInt(rows[i].cells[1].firstChild.data);
}
There are two arguments in the parseInt global function these are a required numeric string, and an optional radix (base).
For decimal it is assumed to be 10, if the radix is not provided.
It will return NaN if the provided string have not contains any number. The parser will change over the number up to the point where a non numeric quality is come to, and give back the outcome if the string contains a halfway number .
Syntax:-
when floating point format reaches the decimal and the integer part of the number is returned if the floating-point format is in the number.
In the event that the string could contain a floating point number and you need the outcome to be a drifting point number, utilize the parse Float worldwide capacity:
Hope this will help you to understand.
Can you help out the community by solving one of the following Javascript problems?
Do activity (Answer, Blog) > Earn Rep Points > Improve Rank > Get more opportunities to work and get paid!
For more topics, questions and answers, please visit the Tech Q&A page.
0 Comment(s)