Improve this Doc View Source

Formats a number as text.

If the input is null or undefined, it will just be returned. If the input is infinite (Infinity or -Infinity), the Infinity symbol '∞' or '-∞' is returned, respectively. If the input is not a number an empty string is returned.

## Usage

### In HTML Template Binding

    {{ number_expression | number : fractionSize}}

### In JavaScript

    $filter('number')(number, fractionSize)

### Arguments

Param | Type | Details
--- | --- | ---
number | number string | Number to format.
fractionSize (optional) | number string | Number of decimal places to round the number to. If this is not provided then the fraction size is computed from the current locale's number formatting pattern. In the case of the default locale, it will be 3.

### Returns

string | Number rounded to `fractionSize` appropriately formatted based on the current locale (e.g., in the en_US locale it will have "." as the decimal separator and include "," group separators after each third digit).

## Examples

    <script>
      angular.module('numberFilterExample', [])
        .controller('ExampleController', ['$scope', function($scope) {
          $scope.val = 1234.56789;
        }]);
    </script>
    <div ng-controller="ExampleController">
      <label>Enter number: <input ng-model='val'></label><br>
      Default formatting: <span id='number-default'>{{val | number}}</span><br>
      No fractions: <span>{{val | number:0}}</span><br>
      Negative number: <span>{{-val | number:4}}</span>
    </div>

     it('should format numbers', function() {
       expect(element(by.id('number-default')).getText()).toBe('1,234.568');
       expect(element(by.binding('val | number:0')).getText()).toBe('1,235');
       expect(element(by.binding('-val | number:4')).getText()).toBe('-1,234.5679');
     });

     it('should update', function() {
       element(by.model('val')).clear();
       element(by.model('val')).sendKeys('3374.333');
       expect(element(by.id('number-default')).getText()).toBe('3,374.333');
       expect(element(by.binding('val | number:0')).getText()).toBe('3,374');
       expect(element(by.binding('-val | number:4')).getText()).toBe('-3,374.3330');
    });