Angular 10 getCurrencySymbol() Method
Last Updated :
24 May, 2021
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:
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:
app.component.ts
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" );
}
|
app.component.html
< h1 >
GeeksforGeeks
</ h1 >
< p >{{curr }} 100</ p >
|
Output:
Example 2:
app.component.ts
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" );
}
|
app.component.html
< h1 >
GeeksforGeeks
</ h1 >
< p >{{curr }} 304</ p >
|
Output:
Reference: https://angular.io/api/common/getCurrencySymbol
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...