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
I solved with an workaround that adapts based on country:
import { Pipe, PipeTransform, LOCALE_ID, Inject } from '@angular/core';
import { getLocaleCurrencySymbol, getLocaleCurrencyName } from
'@angular/common';
@pipe({
name: 'currencyGlobal'
})
export class CurrencyGlobalPipe implements PipeTransform {
constructor(@Inject(LOCALE_ID) public locale: string){
}
transform(value: number): any {
return getLocaleCurrencySymbol(this.locale) + new
Intl.NumberFormat(this.locale, { style: 'decimal', minimumFractionDigits: 2
}).format(value);
}
}
Couldn't use the Intl style:'currency' because the getLocaleCurrencyName doens't return the same as the documentation says it does (https://angular.io/api/common/getLocaleCurrencyName), should be 'USD' but return 'US Dollar', so I did an workaround with currencySimbol + decimal.
Maybe it can help someone else