Reputation: 5733
Is there a possibility with AngularJS to always show two digits after the comma, also if the value is 0. My current code looks like this:
Sum is <b>{{vm.accountsSummary.amountOfPaidAccounts}}</b>
and if vm.accountsSummary.amountOfPaidAccounts is 0 than 0 is shown but 0.00 should be shown. Is there a possibility to do this?
Upvotes: 2
Views: 1843
Reputation: 1135
Try Number filter
{{vm.accountsSummary.amountOfPaidAccounts | number:2}}
Plese refer the link
In Java Script We can use Number filter Like this
$filter('number')(number, fractionSize);
Upvotes: 0
Reputation: 18647
Use number filter,
Syntax
{{ number_expression | number : fractionSize}}
Usage:
Sum is <b>{{vm.accountsSummary.amountOfPaidAccounts | number: 2 }}</b>
Example
var app = angular.module('myApp', []);
app.controller('nCtrl', function($scope) {
$scope.prize = 10;
});
<html>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
<body>
<div ng-app="myApp" ng-controller="nCtrl">
<h1>{{prize | number: 2}}</h1>
</div>
</body>
</html>
Please run this snippet
Upvotes: 2
Reputation: 2939
{{parseFloat(Math.round(vm.accountsSummary.amountOfPaidAccounts * 100) / 100).toFixed(2)}}
Upvotes: 1