本文整理汇总了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;
}
示例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: ' ',