angular float number fraction down

為{幸葍}努か 提交于 2020-01-14 03:14:08

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!