Open In App

Angular forms formatCurrency Directive

In this article, we are going to see what is formatCurrency in Angular 10 and how to use it. The formatCurrency is used to format a number as currency using locale rules.

Syntax:



formatCurrency(value, locale, currency, currencyCode, digitsInfo)

Parameters:

 



Return Value:

NgModule: Module used by formatCurrency is:

Approach: 

Example 1:




import {
  formatCurrency
 }
  from '@angular/common';
  
import {Component,
  Inject,
  LOCALE_ID }
  from '@angular/core';
  
@Component({
selector: 'app-root',
templateUrl: './app.component.html'
})
export class AppComponent {
curr = formatCurrency(10,this.locale,
          'USD');
constructor(
  @Inject(LOCALE_ID) public locale: string,){}
}




<h1>
  GeeksforGeeks
</h1>
  
<p>Locale Currency is : {{curr}}</p>

Output:

Example 2:




import {
  formatCurrency
 }
  from '@angular/common';
  
import {Component,
  Inject,
  LOCALE_ID }
  from '@angular/core';
  
@Component({
selector: 'app-root',
templateUrl: './app.component.html'
})
export class AppComponent {
curr = formatCurrency(10,this.locale,
          'INR');
constructor(
  @Inject(LOCALE_ID) public locale: string,){}
}




<h1>
  GeeksforGeeks
</h1>
  
<p>Locale Currency is : {{curr}}</p>

Output:

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


Article Tags :