javascript - Can not adding up numbers in a column with angular -


im trying sum of column ("price") angular code, have value. example:

price: 5,7,8,9

total price:05789

$scope.totalprice = function(){     var total = 0;     for(count=0;count<$scope.names.length;count++){         var product = $scope.names[count];         total += (product.price);      }     return total; }; 

it looks product.price str, each time use +=, concatenating string.

try using parsefloat or parseint

$scope.totalprice = function(){         var total = 0;         for(count=0;count<$scope.names.length;count++){             var product = $scope.names[count];             total += parsefloat(product.price);          }         return total;          }; 

edit 1:: double checking it, declare var total = 0 , int, += between int , str should give int... weird stuff...

edit 2: well, triple checking it... first thing said ok :d 0 + "0" gives "00"


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -