Reputation: 21617
var grandTotal;
angular.forEach($scope.gear, function(value, key) {
var rowTotal = value.amount * value.price;
console.log(rowTotal);
grandTotal += rowTotal;
});
console.log('grandTotal: '+grandTotal);
I have the above that I'm trying to get a grant total for, It seems to return NaN for my grandTotal
UPDATE:
var grandTotal = 0;
angular.forEach($scope.gear, function(value, key) {
var rowTotal = value.amount * value.price;
rowTotal = rowTotal.toFixed(1);
console.log(rowTotal);
grandTotal += rowTotal;
});
console.log('grandTotal: '+parseFloat(grandTotal));
this returns
Upvotes: 0
Views: 514
Reputation: 2053
What about using vanilla javascript map
and reduce
functions ?
An exemple based on your purpose here : http://jsfiddle.net/optyler/G2ZJa/
Upvotes: 1