I am retrieving data from a table. The data is numbers, but it was saved as TINYTEXT in the mySql database. I can retrieve it and access it just fine, but I'm running into trouble because I need to add numbers.
So while I want 4 + 5 + 3 = 12.... instead I get the result of "453".
This is my calculation on the retrieved data:
let consultingScore = 0;
let consultingScoreDiv = 0;
for (let i = 0; i < result.length; i++){
let tempConScore = result[i].formValue01 +
result[i].formValue02 + result[i].formValue03;
consultingScore = consultingScore + tempConScore;
this.setState({ surveyScoreConsulting: consultingScore }); <--- (This should be 12, but is instead "453"
}
I have tried to use parseInt() like below, but when I do, then the value then becomes NaN. Am I not using parseInt correctly? It seems it should be easier than this to convert sting numbers to integers so I can perform calculations with them.
let consultingScore = 0;
let consultingScoreDiv = 0;
for (let i = 0; i < result.length; i++){
let tempConScore = parseInt(result[i].formValue01) +
parseInt(result[i].formValue02) + parseInt(result[i].formValue03);
consultingScore = consultingScore + tempConScore;
this.setState({ surveyScoreConsulting: consultingScore }); <--- (This should be 12, but is instead "453"
}