angularjs计算中的数学错误

时间:2016-07-13 09:39:51

标签: javascript angularjs

我正在计算值并将总数除以变量值(9)。例如:

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

将是

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

假设是$scope.wald_costs = 8666 但是当我打印<b>{{wald_costs}}</b>时,我没有得到正确的输出。 相反,我得到的输出就像这个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))

我该如何解决这个问题?

2 个答案:

答案 0 :(得分:1)

试试这个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);

答案 1 :(得分:0)

使用

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