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.

WARNING: this pipe uses the Internationalization API which is not yet available in all browsers and may require a polyfill. See 浏览器支持 for details.

Example

  1. @Component({
  2. selector: 'number-pipe',
  3. template: `<div>
  4. <p>e (no formatting): {{e}}</p>
  5. <p>e (3.1-5): {{e | number:'3.1-5'}}</p>
  6. <p>pi (no formatting): {{pi}}</p>
  7. <p>pi (3.5-5): {{pi | number:'3.5-5'}}</p>
  8. </div>`
  9. })
  10. export class NumberPipeComponent {
  11. pi: number = 3.141592;
  12. e: number = 2.718281828459045;
  13. }

NgModule

Description

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