问题
how get number with no fraction in angular in view with filter?
i mean like 1.777
i want to output 1 (angular makes that 2)
how round float number down!
myvalue is 1.777
myvalue| number:0
the output will be 2
how approach to 1?
something like parseInt in jquery i need in view???? is there filter in angular that !
回答1:
It should be simply {{ number_expression | number : fractionSize}}
Markup
<h6>flight duration: {{item.travelTime | number: 0}}</h6></div>
Look at Number filter API
Update
For making round number then you need to use number
filter inside your custom filter.
Markup
<h6>flight duration: {{item.travelTime | numberFormat: 0}}</h6></div>
Filter
app.filter('numberFormat', function($filter){
return function(value, fractionSize){
if(value){
$filter('number')(Math.round(value), fractionSize)
}
}
})
回答2:
angular.module('myApp', ['ui']).filter('parseInt',
function() {
return function(input) {
return parseInt(input);
};
}
);
来源:https://stackoverflow.com/questions/31903318/angular-float-number-fraction-down