Open In App

Angular10 percentPipe

In this article, we are going to see what is percentPipe in Angular 10 and how to use it.

The percentPipe is used to Transform a number to a percentage string.



Syntax:

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

NgModule: Module used by percentPipe is:



Approach:

Input value:

Parameters:

Example 1:

Filename: app.component.ts




import { Component, OnInit } from '@angular/core';
  
@Component({
    selector: 'app-root',
    templateUrl: './app.component.html'
})
export class AppComponent {
    geeks: number = 0.4945;
    gfg: number = 2.343564;
  }

 

 

Filename: app.component.html




<div>
  <p>1st: {{gfg | percent}}</p>
  <p>2nd: {{geeks | percent:'4.3-5'}}</p>
  
</div>

 

 

Output:

 

 

Example 2:

 

Filename: app.component.ts




import { Component, OnInit } from '@angular/core';
  
@Component({
    selector: 'app-root',
    templateUrl: './app.component.html'
})
export class AppComponent {
    geeks: number = 100;
  }

 

 

Filename: app.component.html




<div>
  <p>1st: {{geeks | percent }}</p>
  <p>2nd: {{geeks | percent:'3.4-5' }}</p>
</div>

 

 

Output:

 

 

Reference: https://angular.io/api/common/PercentPipe

 


Article Tags :