0

I am calculating the values and dividing the total by variable value (9).for example:

$scope.wald_costs = Math.round($scope.logistics_costs + $scope.refurbishment_costs + $scope.insurance_costs + $scope.priceful + $scope.t / $scope.$scope.sharable_with)

which will be

$scope.wald_costs = Math.round(1000 + 500 + 4500 + 45000 + 27000 / 9)

suppose to be $scope.wald_costs = 8666 but i am not getting the proper output when i print <b>{{wald_costs}}</b>. Instead what i get in output is like this 6000450003375

$scope.t = 27000 
$scope.logistics_costs = 1000
$scope.refurbishment_costs = 500
$scope.insurance_costs = 4500
$scope.priceful = 45000
$scope.sharable_with = 9

$scope.wald_costs = Math.round(($scope.logistics_costs + $scope.refurbishment_costs + $scope.insurance_costs + $scope.priceful + $scope.t / $scope.$scope.sharable_with))

how can i solve this?

2
  • 2
    If it's supposed to be 8666 then you need to add some parenthesis. Commented Jul 13, 2016 at 9:42
  • Is a typo or you divide only $scope.t by $scope.sharable_with? Commented Jul 13, 2016 at 9:42

2 Answers 2

1

Try this http://plnkr.co/edit/8ZZY2XtxB2EbB64hWYyn?p=preview

$scope.t = 27000; 
$scope.logistics_costs = 1000;
$scope.refurbishment_costs = 500;
$scope.insurance_costs = 4500;
$scope.priceful = 45000;
$scope.sharable_with = 9;
$scope.wald_costs = Math.round(($scope.logistics_costs + $scope.refurbishment_costs + $scope.insurance_costs + $scope.priceful + $scope.t) / $scope.sharable_with);
  alert($scope.wald_costs);
Sign up to request clarification or add additional context in comments.

3 Comments

I tried it, but its concatenating all numbers instead of adding.
what is your expected output , see the plnkr link .
Thanks i solved it. one of the scope variable had text instead of number thats why it was causing problem...
0

use

$scope.wald_costs = Math.round(($scope.logistics_costs + $scope.refurbishment_costs + $scope.insurance_costs + $scope.priceful + $scope.t) / $scope.$scope.sharable_with)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.