Kelyane
Kelyane

Reputation: 467

Angular2 currency pipe EUR format

I already tried to use <span>{{(price | currency: 'EUR': true)}}</span> and { provide: LOCALE_ID, useValue: "de-DE" }. However, server environment is based in USA and I can't change language location there.

Then the standard format is $1,000.00, but I need this format 1.000,00 €

Thank you.

Upvotes: 2

Views: 1452

Answers (1)

LETOURNEUR L&#233;o
LETOURNEUR L&#233;o

Reputation: 311

You can try this (a little bit tricky) :

Declare your custom pipe, it will replace ',' buy '.' and '.' by ',' :

@Pipe({ name: 'customPipe' })
export class ToCustomPipe implements PipeTransform {
    transform(value: string):any {
        if(value == null) return '';
        value = value.toString().replace(/,/, "*");
        value = value.toString().replace(/./, ",");
        value = value.toString().replace(/*/, ".");
        return value;
    }
}

then in your html :

<span>{{(price | currency:'USD':false | customPipe)}} €</span>

Upvotes: 1

Related Questions