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

TypeScript common.DecimalPipe类代码示例

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

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



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

示例1: describe

      describe('transform', () => {
        let pipe: DecimalPipe;
        beforeEach(() => { pipe = new DecimalPipe('en-US'); });

        it('should return correct value for numbers', () => {
          expect(pipe.transform(12345)).toEqual('12,345');
          expect(pipe.transform(123, '.2')).toEqual('123.00');
          expect(pipe.transform(1, '3.')).toEqual('001');
          expect(pipe.transform(1.1, '3.4-5')).toEqual('001.1000');
          expect(pipe.transform(1.123456, '3.4-5')).toEqual('001.12346');
          expect(pipe.transform(1.1234)).toEqual('1.123');
          expect(pipe.transform(1.123456, '.2')).toEqual('1.123');
          expect(pipe.transform(1.123456, '.4')).toEqual('1.1235');
        });

        it('should support strings', () => {
          expect(pipe.transform('12345')).toEqual('12,345');
          expect(pipe.transform('123', '.2')).toEqual('123.00');
          expect(pipe.transform('1', '3.')).toEqual('001');
          expect(pipe.transform('1.1', '3.4-5')).toEqual('001.1000');
          expect(pipe.transform('1.123456', '3.4-5')).toEqual('001.12346');
          expect(pipe.transform('1.1234')).toEqual('1.123');
        });

        it('should not support other objects', () => {
          expect(() => pipe.transform({})).toThrowError();
          expect(() => pipe.transform('123abc')).toThrowError();
        });

        it('should throw if minFractionDigits is explicitly higher than maxFractionDigits', () => {
          expect(() => pipe.transform('1.1', '3.4-2')).toThrowError(/is higher than the maximum/);
        });
      });
开发者ID:MarkPieszak,项目名称:angular,代码行数:33,代码来源:number_pipe_spec.ts


示例2: describe

      describe('transform', () => {
        let pipe: DecimalPipe;
        beforeEach(() => { pipe = new DecimalPipe('en-US'); });

        it('should return correct value for numbers', () => {
          expect(pipe.transform(12345)).toEqual('12,345');
          expect(pipe.transform(1.123456, '3.4-5')).toEqual('001.12346');
        });

        it('should support strings', () => {
          expect(pipe.transform('12345')).toEqual('12,345');
          expect(pipe.transform('123', '.2')).toEqual('123.00');
          expect(pipe.transform('1', '3.')).toEqual('001');
          expect(pipe.transform('1.1', '3.4-5')).toEqual('001.1000');
          expect(pipe.transform('1.123456', '3.4-5')).toEqual('001.12346');
          expect(pipe.transform('1.1234')).toEqual('1.123');
        });

        it('should not support other objects', () => {
          expect(() => pipe.transform({}))
              .toThrowError(
                  `InvalidPipeArgument: '[object Object] is not a number' for pipe 'DecimalPipe'`);
          expect(() => pipe.transform('123abc'))
              .toThrowError(`InvalidPipeArgument: '123abc is not a number' for pipe 'DecimalPipe'`);
        });
      });
开发者ID:IdeaBlade,项目名称:angular,代码行数:26,代码来源:number_pipe_spec.ts


示例3: describe

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

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

        describe('transform', () => {
          it('should return correct value for numbers', () => {
            expect(pipe.transform(12345)).toEqual('12,345');
            expect(pipe.transform(123, '.2')).toEqual('123.00');
            expect(pipe.transform(1, '3.')).toEqual('001');
            expect(pipe.transform(1.1, '3.4-5')).toEqual('001.1000');
            expect(pipe.transform(1.123456, '3.4-5')).toEqual('001.12346');
            expect(pipe.transform(1.1234)).toEqual('1.123');
          });

          it('should support strings', () => {
            expect(pipe.transform('12345')).toEqual('12,345');
            expect(pipe.transform('123', '.2')).toEqual('123.00');
            expect(pipe.transform('1', '3.')).toEqual('001');
            expect(pipe.transform('1.1', '3.4-5')).toEqual('001.1000');
            expect(pipe.transform('1.123456', '3.4-5')).toEqual('001.12346');
            expect(pipe.transform('1.1234')).toEqual('1.123');
          });

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


示例4: 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


示例5: transform

 transform(amount: number, coin: string) {
   return (
     this.decimalPipe.transform(amount / 1e8, '1.2-6') +
     ' ' +
     coin.toUpperCase()
   );
 }
开发者ID:bitpay,项目名称:copay,代码行数:7,代码来源:satToUnit.ts


示例6: formatFiatAmount

  formatFiatAmount(amount: number) {
    let value: any;
    let sep: any;
    let group: any;
    let intValue: any;
    let floatValue: any;
    let finalValue: any;

    value = this.decimalPipe.transform(amount);
    if (!value) return 0;
    sep = value.indexOf(this.formats.DECIMAL_SEP);
    group = value.indexOf(this.formats.GROUP_SEP);

    if (amount >= 0) {
      if (group > 0) {
        if (sep < 0) {
          return value;
        }
        intValue = value.substring(0, sep);
        floatValue = parseFloat(value.substring(sep));
        floatValue = floatValue.toFixed(2);
        floatValue = floatValue.toString().substring(1);
        finalValue = intValue + floatValue;
        return finalValue;
      } else {
        value = parseFloat(value);
        return value.toFixed(2);
      }
    }
    return 0;
  }
开发者ID:bitjson,项目名称:copay,代码行数:31,代码来源:filter.ts


示例7: if

  /**
   * แปลง format ตัวเลข
   * @param value ตัวเลข
   * @param digits จำนวนตำแหน่งทศนิยม
   * @param zeroSymbol สัญลักษณ์แทน 0
   */
  transform(value: string | number, digits?: string, zeroSymbol?: string): string {

    let number: number;

    if (typeof value == 'undefined' || value == 'undefined')
      number = 0
    if (typeof value == 'string') {
      number = Number(value);
      if (value == 'NaN')
        number = 0;
      else if (isNaN(number))
        return value;
    }
    else
      number = value;

    if (isNaN(number))
      number = 0;
    
    if (number != 0)
      return this.decimalPipe.transform(number, digits);
    else {
      if (typeof zeroSymbol != 'undefined')
        return zeroSymbol;
      else
        return '0';
    }
  }
开发者ID:warozz,项目名称:D3VMobiz,代码行数:34,代码来源:number-format.ts


示例8: it

 it('should return correct value for numbers', () => {
   expect(pipe.transform(12345)).toEqual('12,345');
   expect(pipe.transform(123, '.2')).toEqual('123.00');
   expect(pipe.transform(1, '3.')).toEqual('001');
   expect(pipe.transform(1.1, '3.4-5')).toEqual('001.1000');
   expect(pipe.transform(1.123456, '3.4-5')).toEqual('001.12346');
   expect(pipe.transform(1.1234)).toEqual('1.123');
   expect(pipe.transform(1.123456, '.2')).toEqual('1.123');
   expect(pipe.transform(1.123456, '.4')).toEqual('1.1235');
 });
开发者ID:Rowmance,项目名称:angular,代码行数:10,代码来源:number_pipe_spec.ts


示例9: transform

    public transform(value: number, precision?: number): string {
        if (!precision) {
            precision = this.precision;
        }

        /**
         * Min 1 place before the comma and exactly precision places after.
         */
        const digitsInfo = `1.${precision}-${precision}`;
        return this.decimalPipe.transform(value, digitsInfo);
    }
开发者ID:CatoTH,项目名称:OpenSlides,代码行数:11,代码来源:precision.pipe.ts


示例10: it

 it('should support strings', () => {
   expect(pipe.transform('12345')).toEqual('12,345');
   expect(pipe.transform('123', '.2')).toEqual('123.00');
   expect(pipe.transform('1', '3.')).toEqual('001');
   expect(pipe.transform('1.1', '3.4-5')).toEqual('001.1000');
   expect(pipe.transform('1.123456', '3.4-5')).toEqual('001.12346');
   expect(pipe.transform('1.1234')).toEqual('1.123');
 });
开发者ID:AngularLovers,项目名称:angular,代码行数:8,代码来源:number_pipe_spec.ts



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
TypeScript common.DeprecatedCurrencyPipe类代码示例发布时间:2022-05-28
下一篇:
TypeScript common.DatePipe类代码示例发布时间: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