I am using node-mysql and have 2 rows. I am adding together the 'total' column which values are 1.10 and 1.16 obviously expecting total to be 2.26
I am querying the table, and the adding them as follows:
connection.query(q3, function (err, results) {
if (err) throw err;
var totalSum=0;
for(i=0; i<results.length;i++) {
totalSum = totalSum + parseFloat(results[i].total).toFixed(2);
}
However my totalSum returns as 01.101.16 which shows as a concatenation of strings. Why is my parseFloat not changing the string obtained from sql?
Thanks
.toFixed()returns a string, not a number.Number(results[i]).toFixed()is still there that will make absolutely no difference.Number( (results[i].total).toFixed(2) )for converting it back to number but OP shouldn't usetoFixed(2)to begin with