【问题标题】:Angular2 currency pipe EUR formatAngular2货币管道欧元格式
【发布时间】:2017-07-10 14:51:44
【问题描述】:

我已经尝试使用<span>{{(price | currency: 'EUR': true)}}</span>{ provide: LOCALE_ID, useValue: "de-DE" }。但是,服务器环境位于美国,我无法在那里更改语言位置。

那么标准格式是$1,000.00,但我需要这种格式1.000,00 €

谢谢。

【问题讨论】:

    标签: angular pipe currency angular2-pipe


    【解决方案1】:

    你可以试试这个(有点棘手):

    声明您的自定义管道,它将替换“购买”。和 '。'通过',':

    @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;
        }
    }
    

    然后在你的 html 中:

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

    【讨论】:

    • 显示行值错误 = value.toString().replace(/*/, ".");
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-07-05
    • 2017-10-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多