'How i format this @pipe currency with space in angular?

My pipe current print :

{{ 200 | currency:'BRL':true }} = R$200.00

I need include space between R$ in 200.00 would stay correct

{{ 200 | currency:'BRL':true }} = R$ 200.00`

somebody can help me?



Solution 1:[1]

You could chain a custom pipe to add a space

@Pipe({
    name: 'space'
})
export class SpacePipe implements PipeTransform {
    transform(value: any, args?: any): any {
        return value.replace('R$', 'R$ ');
    }
}

{{ 200 | currency:'BRL':true | space }} // R$ 200.00

Solution 2:[2]

Another implementation of accepted answer that I found here. I added a small check since currency symbol is not always at the beginning. Hope this will be useful.

@Pipe({
  name: 'space',
})
export class SpacePipe implements PipeTransform {
  transform(value: any, args?: any): any {
    // Check if first char is a currency symbol and not a number, then add space
    if (isNaN(value.charAt(0))) {
      // will add
      return value.substring(0, 1) + ' ' + value.substring(1);
    } else {
      // Otherwise return initial value
      return value;
    }
  }
}

{{ 634280 | currency:'EUR':'symbol':'': 'en-us' | space }} // € 634,280.00

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 LLai
Solution 2 johannesMatevosyan