If you do not store strings of floats, you do not need to use parseFloat (i), which parses the float from the string. You can rewrite this as:
var nums = [1.99, 5.11, 2.99]; var total = 0; nums.forEach(function(i) { total += i; }); var fixed = total.toFixed(2); console.log(fixed);
or
var nums = [1.99, 5.11, 2.99]; var total = 0; for(var i = 0; i < nums.length; i++){ total += nums[i]; } var fixed = total.toFixed(2); console.log(fixed);
source share