I have problems adding decimals to an array.
Doing it this way:
var array = [2.74, 48.39, 71.45, 85, 38.39];
var sum = 0;
//console.log(array.length);
for (var i = 0; i < array.length; i++) {
console.log(array[i]);
sum += array[i];
}
console.log(sum);
or this:
var array = [2.74, 48.39, 71.45, 85, 38.39];
let sum = array.map(c => parseFloat(c)).reduce((a, b) => a + b, 0);
console.log(sum)
Returns
245.97000000000003
but should be245.97
How should you add decimals to an array?