AngularJS Question

AngularJS, calculation addition (+) is not working

I tried to calculate $scope values through angular controller. For instance: the below code works in order to multiply values inside brackets. However, addition(+) is working like 400+200 = 400200. How to get output 600?

$scope.output = ($scope.quantity.Quantity * $scope.pro_price) + $scope.wait_price;

Answer Source

You need to parse the variable, since your scope variable might be of type string,

$scope.output = ($scope.quantity.Quantity * $scope.pro_price) + parseInt($scope.wait_price);


Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download