Open In App

Angular10 getLocaleCurrencySymbol() Function

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

The getLocaleCurrencySymbol is used to get the currency symbol for the given locale.



Syntax:

getLocaleCurrencySymbol(locale: string): string | null

NgModule: Module used by getLocaleCurrencySymbol is:



Approach: 

import { LOCALE_ID, NgModule } from '@angular/core';

Parameters:

Return value:

Example 1:




import { LOCALE_ID, NgModule } 
        from '@angular/core';
import { BrowserModule } 
        from '@angular/platform-browser';
  
import { AppRoutingModule } 
        from './app-routing.module';
import { AppComponent } 
        from './app.component';
  
@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule,
    AppRoutingModule
  ],
  providers: [
      { provide: LOCALE_ID, useValue: 'en-GB' },
  ],
  bootstrap: [AppComponent]
})
export class AppModule { }




import {FormStyle,
        getLocaleCurrencySymbol, 
        TranslationWidth } 
        from '@angular/common';
  
import {Component, 
        Inject,
        OnInit, 
        LOCALE_ID } 
        from '@angular/core';
  
@Component({
    selector: 'app-root',
    templateUrl: './app.component.html'
})
export class AppComponent {
    sym = getLocaleCurrencySymbol(this.locale);
    constructor(
        @Inject(LOCALE_ID) public locale: string,){}
      }




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

Output:

Example 2:




import { LOCALE_ID, NgModule } 
       from '@angular/core';
import { BrowserModule } 
       from '@angular/platform-browser';
  
import { AppRoutingModule } 
from './app-routing.module';
import { AppComponent } 
from './app.component';
  
@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule,
    AppRoutingModule
  ],
  providers: [
      { provide: LOCALE_ID, useValue: 'en-GB' },
  ],
  bootstrap: [AppComponent]
})
export class AppModule { }




import {FormStyle,
  getLocaleCurrencySymbol, 
  TranslationWidth } 
  from '@angular/common';
  
import { Component, 
  Inject,
  OnInit, 
  LOCALE_ID } 
  from '@angular/core';
  
@Component({
    selector: 'app-root',
    templateUrl: './app.component.html'
})
export class AppComponent {
    sym = getLocaleCurrencySymbol(this.locale);
    constructor(
        @Inject(LOCALE_ID) public locale: string,){}
      }




<h1>
   GeeksforGeeks
</h1>
 <p>Currency symbol is : {{sym}}</p>
 <p>
    {{sym}}100
    {{sym}}200 
    {{sym}}300
    {{sym}}400
    {{sym}}500
 </p>

Output:

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


Article Tags :