当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript js.default.toFixed方法代码示例

本文整理汇总了TypeScript中bignumber.js.default.toFixed方法的典型用法代码示例。如果您正苦于以下问题:TypeScript js.default.toFixed方法的具体用法?TypeScript js.default.toFixed怎么用?TypeScript js.default.toFixed使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在bignumber.js.default的用法示例。


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

示例1: explainTransaction

  /**
   * Explain/parse transaction
   * @param params
   * - txBase64: transaction encoded as base64 string
   * @returns {{displayOrder: [string,string,string,string,string], id: *, outputs: Array, changeOutputs: Array}}
   */
  explainTransaction(params) {
    const { txBase64 } = params;
    let tx;

    try {
      tx = new stellar.Transaction(txBase64);
    } catch (e) {
      throw new Error('txBase64 needs to be a valid tx encoded as base64 string');
    }
    const id = tx.hash().toString('hex');
    const explanation: any = {
      displayOrder: ['id', 'outputAmount', 'changeAmount', 'outputs', 'changeOutputs', 'fee', 'memo'],
      id,
      outputs: [],
      changeOutputs: [],
      memo: {}
    };

    // In a Stellar tx, the _memo property is an object with the methods:
    // value() and arm() that provide memo value and type, respectively.
    if (_.result(tx, '_memo.value') && _.result(tx, '_memo.arm')) {
      explanation.memo = {
        value: _.result(tx, '_memo.value').toString(),
        type: _.result(tx, '_memo.arm')
      };
    }

    let spendAmount = new BigNumber(0);
    // Process only operations of the native asset (XLM)
    const operations = _.filter(tx.operations, operation => !operation.asset || operation.asset.getCode() === 'XLM');
    if (_.isEmpty(operations)) {
      throw new Error('missing operations');
    }
    explanation.outputs = _.map(operations, operation => {
      // Get memo to attach to address, if type is 'id'
      const memoId = (_.get(explanation, 'memo.type') === 'id' && ! _.get(explanation, 'memo.value') ? `?memoId=${explanation.memo.value}` : '');
      const output = {
        amount: this.bigUnitsToBaseUnits(operation.startingBalance || operation.amount),
        address: operation.destination + memoId
      };
      spendAmount = spendAmount.plus(output.amount);
      return output;
    });

    explanation.outputAmount = spendAmount.toFixed(0);
    explanation.changeAmount = '0';

    explanation.fee = {
      fee: tx.fee.toFixed(0),
      feeRate: null,
      size: null
    };
    return explanation;
  }
开发者ID:BitGo,项目名称:BitGoJS,代码行数:60,代码来源:xlm.ts

示例2: BigNumber

    x.toExponential()               // '4.56e+1'
    y.toExponential()               // '4.56e+1'
    x.toExponential(0)              // '5e+1'
    y.toExponential(0)              // '5e+1'
    x.toExponential(1)              // '4.6e+1'
    y.toExponential(1)              // '4.6e+1'
    y.toExponential(1, 1)           // '4.5e+1'  (ROUND_DOWN)
    x.toExponential(3)              // '4.560e+1'
    y.toExponential(3)              // '4.560e+1'
}

{
    const x = 3.456
    const y = new BigNumber(x)
    x.toFixed()                     // '3'
    y.toFixed()                     // '3.456'
    y.toFixed(0)                    // '3'
    x.toFixed(2)                    // '3.46'
    y.toFixed(2)                    // '3.46'
    y.toFixed(2, 1)                 // '3.45'  (ROUND_DOWN)
    x.toFixed(5)                    // '3.45600'
    y.toFixed(5)                    // '3.45600'
}

{
    const format = {
        decimalSeparator: '.',
        groupSeparator: ',',
        groupSize: 3,
        secondaryGroupSize: 0,
        fractionGroupSeparator: ' ',
开发者ID:felixfbecker,项目名称:typed-bignumber.js,代码行数:31,代码来源:test.ts


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