Reputation: 778
I have a an input form with the following html
Which prints price as {{item.myvalue}}
if I enter the price as 2.15 it prints as 2.15. However, if I enter it as 2.00 it prints as 2. I would like to print it as 2.00. How do I go about it?
Upvotes: 2
Views: 2951
Reputation: 7754
You can do it using a custom filter:
angular.module('app')
.filter('fixTwoDecimal', function() {
return function(num) {
if(!num) return;
var result = String(num);
if(result.indexOf('.') === -1) result = result + '.00';
else {
var parts = result.split('.');
if(parts[1].length === 1) result = result + '0';
}
return result;
}
});
Upvotes: 0