當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript common.DecimalPipe類代碼示例

本文整理匯總了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;未經允許,請勿轉載。