2

I am working on angularjs i have getting this problem

{{420/60}} will display 7

that is fine for me.

But when i am try this with 450 then it will display 7.5 i want to display only 7 i.e only integer number.

{{450/60 }} will display 7.5 but need only 7

if i used this

{{450/60 | number : 0}} then output is 8

because it will round of the text.please help me i want to display only 7.

2 Answers 2

4

Set $scope.Math = window.Math in your controller:

  var app = angular.module('app',[]);
  app.controller('ctrl', function($scope) {
      $scope.Math = window.Math;
  });

Then in your HTML, you can use Math.floor:

  <body ng-app="app" ng-controller="ctrl">
     {{ Math.floor(12/5) }} // outputs 2
  </body>
Sign up to request clarification or add additional context in comments.

Comments

0

Define a directive like so:

angular.module('myApp',[]).filter('floor', function(){
    return function(n){
        return Math.floor(n);
    };
});

Then you can simply do {{ 450/60 | floor }}.

2 Comments

Thanks but need to set scope also as $scope.Math = window.Math;
Yes, that is correct. Sorry about the omission, I actually edited the answer and went in a different direction.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.