In this article, we are going to see what is getCurrencySymbol in Angular 10 and how to use it. getCurrencySymbol is used to retrieve the currency symbol for a given currency code
Syntax:
getCurrencySymbol(code, locale, format)
Parameters:
- code: The currency code
- locale: A locale code for the locale format rule to use.
- format: The format.
Return Value:
- string: the formatted date string.
NgModule: Module used by getCurrencySymbol is:
- CommonModule
Approach:
- Create the Angular app to be used.
- In app.module.ts import LOCALE_ID because we need locale to be imported for using get getCurrencySymbol.
import { LOCALE_ID, NgModule } from '@angular/core';- In app.component.ts import getCurrencySymbol and LOCALE_ID
- inject LOCALE_ID as a public variable.
- In app.component.html show the local variable using string interpolation
- Serve the angular app using ng serve to see the output.
Example 1:
import {
getCurrencySymbol
}
from '@angular/common';
import {Component}
from '@angular/core';
@Component({
selector: 'app-root',
templateUrl: './app.component.html'
})
export class AppComponent {
curr = getCurrencySymbol("USD", "wide");
}
<h1>
GeeksforGeeks
</h1>
<p>{{curr }} 100</p>
Output:
Example 2:
import {
getCurrencySymbol
}
from '@angular/common';
import {Component}
from '@angular/core';
@Component({
selector: 'app-root',
templateUrl: './app.component.html'
})
export class AppComponent {
curr = getCurrencySymbol("INR", "narrow");
}
<h1>
GeeksforGeeks
</h1>
<p>{{curr }} 304</p>
Output:
Reference: https://v17.angular.io/api/common/getCurrencySymbol