Help Angular by taking a 1 minute survey!Go to surveyHome

PercentPipe

Transforms a number to a percentage string, formatted according to locale rules that determine group sizing and separator, decimal-point character, and other locale-specific configurations.

{{ value_expression | percent [ : digitsInfo [ : locale ] ] }}
      
      {{ value_expression | percent [ : digitsInfo [ : locale ] ] }}
    

NgModule

Input value

value any

The number to be formatted as a percentage.

Parameters

digitsInfo string

Decimal representation options, specified by a string in the following format:
{minIntegerDigits}.{minFractionDigits}-{maxFractionDigits}.

  • minIntegerDigits: The minimum number of integer digits before the decimal point. Default is 1.
  • minFractionDigits: The minimum number of digits after the decimal point. Default is 0.
  • maxFractionDigits: The maximum number of digits after the decimal point. Default is 0.

Optional. Default is undefined.

locale string

A locale code for the locale format rules to use. When not supplied, uses the value of LOCALE_ID, which is en-US by default. See Setting your app locale.

Optional. Default is undefined.

See also

Usage notes

The following code shows how the pipe transforms numbers into text strings, according to various format specifications, where the caller's default locale is en-US.

@Component({ selector: 'percent-pipe', template: `<div> <!--output '26%'--> <p>A: {{a | percent}}</p> <!--output '0,134.950%'--> <p>B: {{b | percent:'4.3-5'}}</p> <!--output '0 134,950 %'--> <p>B: {{b | percent:'4.3-5':'fr'}}</p> </div>` }) export class PercentPipeComponent { a: number = 0.259; b: number = 1.3495; }
      
      
  1. @Component({
  2. selector: 'percent-pipe',
  3. template: `<div>
  4. <!--output '26%'-->
  5. <p>A: {{a | percent}}</p>
  6.  
  7. <!--output '0,134.950%'-->
  8. <p>B: {{b | percent:'4.3-5'}}</p>
  9.  
  10. <!--output '0 134,950 %'-->
  11. <p>B: {{b | percent:'4.3-5':'fr'}}</p>
  12. </div>`
  13. })
  14. export class PercentPipeComponent {
  15. a: number = 0.259;
  16. b: number = 1.3495;
  17. }