• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript common.CurrencyPipe类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了TypeScript中@angular/common.CurrencyPipe的典型用法代码示例。如果您正苦于以下问题:TypeScript CurrencyPipe类的具体用法?TypeScript CurrencyPipe怎么用?TypeScript CurrencyPipe使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了CurrencyPipe类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。

示例1: describe

    describe('CurrencyPipe', () => {
      let pipe: CurrencyPipe;

      beforeEach(() => { pipe = new CurrencyPipe('en-US'); });

      describe('transform', () => {
        it('should return correct value for numbers', () => {
          expect(pipe.transform(123)).toEqual('$123.00');
          expect(pipe.transform(12, 'EUR', 'code', '.1')).toEqual('EUR12.0');
          expect(pipe.transform(5.1234, 'USD', 'code', '.0-3')).toEqual('USD5.123');
          expect(pipe.transform(5.1234, 'USD', 'code')).toEqual('USD5.12');
          expect(pipe.transform(5.1234, 'USD', 'symbol')).toEqual('$5.12');
          expect(pipe.transform(5.1234, 'CAD', 'symbol')).toEqual('CA$5.12');
          expect(pipe.transform(5.1234, 'CAD', 'symbol-narrow')).toEqual('$5.12');
          expect(pipe.transform(5.1234, 'CAD', 'symbol-narrow', '5.2-2')).toEqual('$00,005.12');
          expect(pipe.transform(5.1234, 'CAD', 'symbol-narrow', '5.2-2', 'fr'))
              .toEqual('00 005,12 $');
        });

        it('should not support other objects', () => {
          expect(() => pipe.transform({}))
              .toThrowError(
                  `InvalidPipeArgument: '[object Object] is not a number' for pipe 'CurrencyPipe'`);
        });

        it('should warn if you are using the v4 signature', () => {
          const warnSpy = spyOn(console, 'warn');
          pipe.transform(123, 'USD', true);
          expect(warnSpy).toHaveBeenCalledWith(
              `Warning: the currency pipe has been changed in Angular v5. The symbolDisplay option (third parameter) is now a string instead of a boolean. The accepted values are "code", "symbol" or "symbol-narrow".`);
        });
      });
    });
开发者ID:Rowmance,项目名称:angular,代码行数:33,代码来源:number_pipe_spec.ts


示例2: constructor

    constructor(i18nService: I18nService, platformUtilsService: PlatformUtilsService,
        tokenService: TokenService, apiService: ApiService,
        private currencyPipe: CurrencyPipe) {
        super(i18nService, platformUtilsService, tokenService, apiService);

        // Support old price string. Can be removed in future once all translations are properly updated.
        const thePrice = this.currencyPipe.transform(this.price, '$');
        this.priceString = i18nService.t('premiumPrice', thePrice);
        if (this.priceString.indexOf('%price%') > -1) {
            this.priceString = this.priceString.replace('%price%', thePrice);
        }
    }
开发者ID:bitwarden,项目名称:browser,代码行数:12,代码来源:premium.component.ts


示例3: describe

      describe('CurrencyPipe', () => {
        var pipe: CurrencyPipe;

        beforeEach(() => { pipe = new CurrencyPipe(); });

        describe('transform', () => {
          it('should return correct value for numbers', () => {
            expect(pipe.transform(123)).toEqual('USD123.00');
            expect(pipe.transform(12, 'EUR', false, '.1')).toEqual('EUR12.0');
            expect(pipe.transform(5.1234, 'USD', false, '.0-3')).toEqual('USD5.123');
          });

          it('should not support other objects',
             () => { expect(() => pipe.transform(new Object())).toThrowError(); });
        });
      });
开发者ID:AngularLovers,项目名称:angular,代码行数:16,代码来源:number_pipe_spec.ts


示例4: describe

    describe('CurrencyPipe', () => {
      let pipe: CurrencyPipe;

      beforeEach(() => { pipe = new CurrencyPipe('en-US'); });

      describe('transform', () => {
        it('should return correct value for numbers', () => {
          expect(pipe.transform(123)).toEqual('$123.00');
          expect(pipe.transform(12, 'EUR', 'code', '.1')).toEqual('EUR12.0');
          expect(pipe.transform(5.1234, 'USD', 'code', '.0-3')).toEqual('USD5.123');
          expect(pipe.transform(5.1234, 'USD', 'code')).toEqual('USD5.12');
          expect(pipe.transform(5.1234, 'USD', 'symbol')).toEqual('$5.12');
          expect(pipe.transform(5.1234, 'CAD', 'symbol')).toEqual('CA$5.12');
          expect(pipe.transform(5.1234, 'CAD', 'symbol-narrow')).toEqual('$5.12');
          expect(pipe.transform(5.1234, 'CAD', 'symbol-narrow', '5.2-2')).toEqual('$00,005.12');
          expect(pipe.transform(5.1234, 'CAD', 'symbol-narrow', '5.2-2', 'fr'))
              .toEqual('00 005,12 $');
          expect(pipe.transform(5, 'USD', 'symbol', '', 'fr')).toEqual('5,00 $US');
          expect(pipe.transform(123456789, 'EUR', 'symbol', '', 'de-at'))
              .toEqual('€ 123.456.789,00');
        });

        it('should support any currency code name', () => {
          // currency code is unknown, default formatting options will be used
          expect(pipe.transform(5.1234, 'unexisting_ISO_code', 'symbol'))
              .toEqual('unexisting_ISO_code5.12');
          // currency code is USD, the pipe will format based on USD but will display "Custom name"
          expect(pipe.transform(5.1234, 'USD', 'Custom name')).toEqual('Custom name5.12');
        });

        it('should not support other objects', () => {
          expect(() => pipe.transform({}))
              .toThrowError(
                  `InvalidPipeArgument: '[object Object] is not a number' for pipe 'CurrencyPipe'`);
        });

        it('should warn if you are using the v4 signature', () => {
          const warnSpy = spyOn(console, 'warn');
          pipe.transform(123, 'USD', true);
          expect(warnSpy).toHaveBeenCalledWith(
              `Warning: the currency pipe has been changed in Angular v5. The symbolDisplay option (third parameter) is now a string instead of a boolean. The accepted values are "code", "symbol" or "symbol-narrow".`);
        });
      });
    });
开发者ID:DeepanParikh,项目名称:angular,代码行数:44,代码来源:number_pipe_spec.ts


示例5: if

    transform(value: number, ...args: any[]): any {
        let assetInfo = args.find(a => a instanceof Assets || a instanceof Object) as Assets;
        let currency = args.find(a => typeof a === "string") as string;
        let showCurrency = args.find(a => typeof a === "boolean");
        if (showCurrency === undefined) {
            showCurrency = true;
        }

        if (assetInfo && currency) {
            let asset = assetInfo[currency] ? assetInfo[currency] :
                (assetInfo['X' + currency] ? assetInfo['X' + currency] : null);
            //(assetInfo['Z' + currency] ? assetInfo['Z' + currency] : null));
            if (!asset && currency.startsWith('Z') && currency !== 'ZBT') {
                return this.currencyPipe.transform(value, currency.substring(1, currency.length), true);
            }
            else if (!asset) {
                return this.decimalPipe.transform(value, '1.5-5');
            }
            if (asset.assetClass === 'currency' && currency.startsWith('Z') && currency !== 'ZBT') {
                return this.currencyPipe.transform(value, currency.substring(1, currency.length), true);
            }
            let displayDecimals = asset.displayDecimals.toString();
            return this.decimalPipe.transform(value, '1.' + displayDecimals + '-' + displayDecimals);
        } else if (currency) {
            return this.currencyPipe.transform(value, currency.startsWith('Z') ? currency.substring(1, currency.length) : currency, true);
        }

        return this.decimalPipe.transform(value, '1.2-2');

    }
开发者ID:wallaceiam,项目名称:mKraken,代码行数:30,代码来源:cryptocurrency.pipe.ts


示例6: it

 it('should support any currency code name', () => {
   // currency code is unknown, default formatting options will be used
   expect(pipe.transform(5.1234, 'unexisting_ISO_code', 'symbol'))
       .toEqual('unexisting_ISO_code5.12');
   // currency code is USD, the pipe will format based on USD but will display "Custom name"
   expect(pipe.transform(5.1234, 'USD', 'Custom name')).toEqual('Custom name5.12');
 });
开发者ID:IdeaBlade,项目名称:angular,代码行数:7,代码来源:number_pipe_spec.ts


示例7: it

 it('should return correct value for numbers', () => {
   // In old Chrome, default formatiing for USD is different
   if (browserDetection.isOldChrome) {
     expect(normalize(pipe.transform(123))).toEqual('USD123');
   } else {
     expect(normalize(pipe.transform(123))).toEqual('USD123.00');
   }
   expect(normalize(pipe.transform(12, 'EUR', false, '.1'))).toEqual('EUR12.0');
   expect(normalize(pipe.transform(5.1234, 'USD', false, '.0-3'))).toEqual('USD5.123');
 });
开发者ID:JanStureNielsen,项目名称:angular,代码行数:10,代码来源:number_pipe_spec.ts


示例8: getLastVolumeTo

 getLastVolumeTo(): string {
   if (this.tickerData.TOSYMBOL == 'USD') {
     return this.currencyPipe.transform(this.tickerData.LASTVOLUMETO, this.tickerData.TOSYMBOL, true, '0.2-2');
     // return "tickerData.PRICE | currency:tickerData.TOSYMBOL:true"
   }
   else {
     let trade_pair_key: string = "USD_" + this.tickerData.TOSYMBOL;
     return this.currencyPipe.transform(this.tickerData.LASTVOLUMETO, this.tickerData.TOSYMBOL, true) + ' ( ' +
       this.currencyPipe.transform(this.tickerData.LASTVOLUMETO/this.cryptoCompareService.exchangeRates.get(trade_pair_key), 'USD', true, '0.2-2') + ' ) ';
   }
 }
开发者ID:funnyData,项目名称:crypto-arb-tracker,代码行数:11,代码来源:trading-pair-card.component.ts


示例9: currencyFmt

 public currencyFmt( val) {
   console.log( val);
   let v = val.replace( /[^\d]/g,'');
   v = (+v)/100;
   console.log( v);
   let x = this.currencyPipe.transform(v, 'USD', true, '1.2-2' ); // this.accountNumberFormat(value);
   console.log( x);
   return x;
 }
开发者ID:dmostroff,项目名称:ccpoints,代码行数:9,代码来源:utils.service.ts



注:本文中的@angular/common.CurrencyPipe类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript common.DatePipe类代码示例发布时间:2022-05-28
下一篇:
TypeScript common.ControlGroup类代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap