How to display the currency symbol to the right in Angular

前端 未结 8 1399
花落未央
花落未央 2020-12-15 04:37

I have to display Euro currency like this : 583 €.

But with this code:

{{ price | currency:\'EUR\':true }}

I get

8条回答
  •  渐次进展
    2020-12-15 04:56

    I just didn't want to use 'fr' local, So :

    import { PipeTransform} from '@angular/core';
    import { Pipe } from '@angular/core';
    import {CurrencyPipe} from '@angular/common';
    
        @Pipe({ name: 'myCurrency' })
        export class MyCurrencyPipe extends CurrencyPipe implements PipeTransform {
        
          transform(value: any, currencyCode?: string, display?: 'code' | 'symbol' | 'symbol-narrow' | string | boolean, digitsInfo?: string, locale?: string): string | null {
             let result = super.transform(value, currencyCode, display, digitsInfo, locale);
             if (result.charAt(0)==='₽' || result.charAt(0)==='$' ){
               result = result.substr(1)+' ' +result.substr(0,1);
             }else if(result.substr(0,3)==="TJS" || result.substr(0,3)==="RUB"){
               result = result.substr(3) +" "+result.substr(0,3)
             }
             if ( Number(value) >0 ){
               result = "+ "+ result
             }else{
               result = "- "+ result
             }
             return result;
          }
    
    }
    

提交回复
热议问题