1

As per the angular number format filter, if I give this

       $scope.numberExpression =123.45;

      {{ numberExpression | number : 2}} // returns 123.45

and if it is $scope.numberExpression =123;

     {{ numberExpression | number : 2}} // returns 123.00

But I dont want the 00 appended there . Is there a way to do this by using number filter .

2 Answers 2

1

You can use:

{{numberExpression | number : ((numberExpression % 1 === 0) ? 0 : 2)}} 
Sign up to request clarification or add additional context in comments.

Comments

1

You can use number than number:2 Plunkr Demo

{{numberExpression  | number}}

 angular.module('numberFilterExample', [])
    .controller('ExampleController', ['$scope', function($scope) {
      $scope.val = 123.00;
    }]);
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<body ng-app="numberFilterExample">

<div ng-controller="ExampleController">
  Enter number: <input ng-model='val'><br>
  First example: <span id='number-default'> {{ val | number : 2}}</span><br>
  Second Example: <span>{{val | number}}</span>
</div>
</body>

Comments

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.