Angular 2 formatting currency BRL format

前端 未结 11 2478
梦毁少年i
梦毁少年i 2021-02-19 14:52

I\'m trying to use pipe to format the price of an item in PT-BR currency format.

Here what i\'m trying to do:

{{statement
11条回答
  •  余生分开走
    2021-02-19 15:23

    I solve....

    import { Pipe, PipeTransform } from '@angular/core';
    import { CurrencyPipe } from '@angular/common';
    
    @Pipe({
      name: 'currencyformat'
    })
    export class CurrencyFormatPipe implements PipeTransform {
    
      transform(value: number, currencyCode: string = 'BRL', symbolDisplay: boolean = true, digits?: string): string {
        if (!value) {
          return '';
        }
    
        let currencyPipe: CurrencyPipe = new CurrencyPipe('pt-BR');
        let newValue: string = currencyPipe.transform(value, currencyCode, symbolDisplay, digits);
    
        return newValue;
      }
    
    }
    

提交回复
热议问题