I have a the following statement in my Javascript controller:
$scope.myList = [0, 1, 0.5, 0.6666666];
My AngularJS template contains the follow
As the other answers didn't really work well, or did not not incorporate or work with Angular's $locale service, I wrote the following filter
:
Template:
{{yourNumber | roundTo: N}}
Filter:
app.filter('roundTo', function(numberFilter) {
return function(value, maxDecimals) {
return numberFilter((value || 0)
.toFixed(maxDecimals)
.replace(/(?:\.0+|(\.\d+?)0+)$/, "$1")
);
}
})
Rounds the number to the max number of decimals
Trims all trailing zero's
Removes the decimal seperator when it's not needed
And Uses Angular's $locale formatting