本文整理汇总了TypeScript中bignumber.js.default.toString方法的典型用法代码示例。如果您正苦于以下问题:TypeScript js.default.toString方法的具体用法?TypeScript js.default.toString怎么用?TypeScript js.default.toString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类bignumber.js.default
的用法示例。
在下文中一共展示了js.default.toString方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: it
it('Logs a few donations and reads them', async () => {
await db.updateCreator(c_url, c_name);
const creatorId = (await db.getCreator(c_url)).id;
await db.logDonation(
creatorId,
weiAmount.toString(),
usdAmount.toString(),
txHash
);
await db.logDonation(
creatorId,
weiAmount.mul('2').toString(),
usdAmount.mul('2').toString(),
'0xe46e63549fc0453da0afa8ac79a87b4baae9a70759a82bee19abd81665b0463b'
);
await db.logDonation(
creatorId,
weiAmount.mul('3').toString(),
usdAmount.mul('3').toString(),
'0x42bd00f4701b7d24dc3e3acd0ee7c7333e57c2b77532f012994bbcefca7cc726'
);
const donations = await db.getDonations();
expect(donations[1].usdAmount.toString()).toEqual(
usdAmount.mul('2').toString()
);
});
示例2: bigNumberToBuffer
export function bigNumberToBuffer (value: BigNumber, length?: number): Buffer {
const lengthOfValue = (length !== undefined ? length : Math.ceil(value.toString(2).length / 8))
const buffer = Buffer.alloc(lengthOfValue)
let big = value
for (let i = buffer.length - 1; i >= 0; i--) {
buffer.writeUInt8(big.modulo(256).toNumber(), i)
big = big.dividedToIntegerBy(256)
}
return buffer
}
示例3: prepareFee
function prepareFee(): Promise<TransactionJSON> {
// instructions.fee is scaled (for multi-signed transactions) while txJSON.Fee is not.
// Due to this difference, we do NOT allow both to be set, as the behavior would be complex and
// potentially ambiguous.
// Furthermore, txJSON.Fee is in drops while instructions.fee is in XRP, which would just add to
// the confusion. It is simpler to require that only one is used.
if (txJSON.Fee && instructions.fee) {
return Promise.reject(new ValidationError('`Fee` in txJSON and `fee` in `instructions` cannot both be set'))
}
if (txJSON.Fee) {
// txJSON.Fee is set. Use this value and do not scale it.
return Promise.resolve(txJSON)
}
const multiplier = instructions.signersCount === undefined ? 1 :
instructions.signersCount + 1
if (instructions.fee !== undefined) {
const fee = new BigNumber(instructions.fee)
if (fee.greaterThan(api._maxFeeXRP)) {
return Promise.reject(new ValidationError(`Fee of ${fee.toString(10)} XRP exceeds ` +
`max of ${api._maxFeeXRP} XRP. To use this fee, increase ` +
'`maxFeeXRP` in the RippleAPI constructor.'))
}
txJSON.Fee = scaleValue(common.xrpToDrops(instructions.fee), multiplier)
return Promise.resolve(txJSON)
}
const cushion = api._feeCushion
return api.getFee(cushion).then(fee => {
return api.connection.getFeeRef().then(feeRef => {
const extraFee =
(txJSON.TransactionType !== 'EscrowFinish' ||
txJSON.Fulfillment === undefined) ? 0 :
(cushion * feeRef * (32 + Math.floor(
Buffer.from(txJSON.Fulfillment, 'hex').length / 16)))
const feeDrops = common.xrpToDrops(fee)
const maxFeeXRP = instructions.maxFee ?
BigNumber.min(api._maxFeeXRP, instructions.maxFee) : api._maxFeeXRP
const maxFeeDrops = common.xrpToDrops(maxFeeXRP)
const normalFee = scaleValue(feeDrops, multiplier, extraFee)
txJSON.Fee = BigNumber.min(normalFee, maxFeeDrops).toString(10)
return txJSON
})
})
}
示例4: BigNumber
{
const x = 45.6
const y = new BigNumber(x)
x.toPrecision() // '45.6'
y.toPrecision() // '45.6'
x.toPrecision(1) // '5e+1'
y.toPrecision(1) // '5e+1'
y.toPrecision(2, 0) // '4.6e+1' (ROUND_UP)
y.toPrecision(2, 1) // '4.5e+1' (ROUND_DOWN)
x.toPrecision(5) // '45.600'
y.toPrecision(5) // '45.600'
}
{
const x = new BigNumber(750000)
x.toString() // '750000'
BigNumber.config({ EXPONENTIAL_AT: 5 })
x.toString() // '7.5e+5'
}
{
const y = new BigNumber(362.875)
y.toString(2) // '101101010.111'
y.toString(9) // '442.77777777777777777778'
y.toString(32) // 'ba.s'
}
{
BigNumber.config({ DECIMAL_PLACES: 4 });
const z = new BigNumber('1.23456789')
z.toString() // '1.23456789'
示例5: computeBigNumberBufferSize
function computeBigNumberBufferSize (value: BigNumber): number {
return Math.ceil(value.toString(16).length / 2)
}
示例6: BigNumber
export interface Precision {
decimals: number;
limit: string;
zero: string;
multiple: string;
}
const ten = new BigNumber(10, 10);
const decimals = new BigNumber(18, 10);
const multiple: BigNumber = ten.exponentiatedBy(decimals.toNumber());
export const PRECISION: Precision = {
decimals: decimals.toNumber(),
limit: ten.dividedBy(multiple).toString(),
zero: new BigNumber(1, 10).dividedBy(multiple).toString(),
multiple: multiple.toString(),
};
// WARNING: Update this only if this release requires destroying all existing Augur Node Databases
export const DB_VERSION = 4;
export const DB_FILE = "augur-%s-%s.db";
export const DB_WARP_SYNC_FILE = "%s-%s-%s.warp";
export const DB_WARP_SYNC_FILE_ENDING = "-%s-%s.warp";
export const DUMP_EVERY_BLOCKS = 100;
export const ETHER = "ether";
export const MINIMUM_TRADE_SIZE = "0.000001";
export const BN_WEI_PER_ETHER: BigNumber = new BigNumber(10, 10).exponentiatedBy(18);
export const WEI_PER_ETHER: string = BN_WEI_PER_ETHER.toString();