得到任何给定值angularjs的25%



考虑到我有一个可以不时包含任何值的模型。这是的值

$scope.getTotalValue could be 100, 200 or even 6000.

现在我想计算getTotalValue模型中实际值的25%

$scope.calculatePercentage = (25/100)*(1/$scope.getTotalValue)

我面临的挑战是,当结果以0开始时,并没有给我25的实际百分比。

如果你想要一个固定的百分比,比如25%,只需将你的值乘以0.25:

$scope.calculatePercentage = $scope.getTotalValue * 0.25;

这就是25 / 100,即25%(即一百(。

通过这种方式,您可以计算给定数字的百分比:

$scope.getTotalValue = 100;
$scope.calculatePercentage = (($scope.getTotalValue/100)*25)
console.log($scope.calculatePercentage)

您所需要做的就是将特定值乘以0.25。让我告诉你为什么。。。25% of something25/100 of something相同,只是0.25 of something.

因此,获得$scope.getTotalValue25%所需的代码为:

$scope.calculatePercentage = $scope.getTotalValue * 0.25;

应该可以。希望这能有所帮助。

最新更新