DecimalPipe

Stable Pipe

What it does

Formats a number according to locale rules.

How to use

number_expression | number[:digitInfo]

Formats a number as text. Group sizing and separator and other locale-specific configurations are based on the active locale.

where expression is a number:

  • digitInfo is a string which has a following format: {minIntegerDigits}.{minFractionDigits}-{maxFractionDigits}
    • minIntegerDigits is the minimum number of integer digits to use. Defaults to 1.
    • minFractionDigits is the minimum number of digits after fraction. Defaults to 0.
    • maxFractionDigits is the maximum number of digits after fraction. Defaults to 3.

For more information on the acceptable range for each of these numbers and other details see your native internationalization library.

WARNING: this pipe uses the Internationalization API which is not yet available in all browsers and may require a polyfill. See Browser support for details.

Example

@Component({
  selector: 'number-pipe',
  template: `<div>
    <p>e (no formatting): {{e}}</p>
    <p>e (3.1-5): {{e | number:'3.1-5'}}</p>
    <p>pi (no formatting): {{pi}}</p>
    <p>pi (3.5-5): {{pi | number:'3.5-5'}}</p>
  </div>`
})
export class NumberPipeComponent {
  pi: number = 3.141592;
  e: number = 2.718281828459045;
}

NgModule

CommonModule

Description

exported from @angular/common/index defined in @angular/common/src/pipes/number_pipe.ts

© 2010–2017 Google, Inc.
Licensed under the Creative Commons Attribution License 4.0.
https://v2.angular.io/docs/ts/latest/api/common/index/DecimalPipe-pipe.html