How to round in Javascript/Angular JS — but remove insignificant digits

前端 未结 3 1692
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-02-18 21:49

I have a the following statement in my Javascript controller:

$scope.myList = [0, 1, 0.5, 0.6666666];

My AngularJS template contains the follow

3条回答
  •  轮回少年
    2021-02-18 22:31

    I would do it like this:

    {{formatNumber(i)}}

    and in your controller:

    $scope.formatNumber = function(i) {
        return Math.round(i * 100)/100; 
    }
    

提交回复
热议问题