本文整理汇总了TypeScript中bignumber.js.default.toNumber方法的典型用法代码示例。如果您正苦于以下问题:TypeScript js.default.toNumber方法的具体用法?TypeScript js.default.toNumber怎么用?TypeScript js.default.toNumber使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类bignumber.js.default
的用法示例。
在下文中一共展示了js.default.toNumber方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: numberParser
export function numberParser(notation: string) {
let bigNum: BigNumber;
if (!numberMatcher.test(notation)) {
bigNum = new BigNumber(NaN);
}
else if (/[eE]/.test(notation)) {
const [base, power] = notation.split(/[eE]/);
bigNum = new BigNumber(base).multipliedBy(Math.pow(10, Number(power)));
}
else if (/[puμnmkMG]$/.test(notation)) {
const base = notation.substring(0, notation.length - 1);
const rankOri = notation[notation.length - 1];
const rank = rankOri === 'u' ? 'μ' : rankOri;
const power = RankEnum[rank];
bigNum = new BigNumber(base).multipliedBy(Math.pow(10, power));
}
else {
bigNum = new BigNumber(notation);
}
return bigNum.toNumber();
}
示例2: BigNumber
const y = new BigNumber(235.4325)
const z = new BigNumber('0.0098074')
// Serialize an array of three BigNumbers
const str = JSON.stringify([x, y, z])
// "["1.777e+459","235.4325","0.0098074"]"
// Return an array of three BigNumbers
JSON.parse(str, function (key, val) {
return key === '' ? val : new BigNumber(val)
})
}
{
const x = new BigNumber(456.789)
x.toNumber() // 456.789
const y = new BigNumber('45987349857634085409857349856430985')
y.toNumber() // 4.598734985763409e+34
const z = new BigNumber(-0)
1 / +z // Infinity
1 / z.toNumber() // -Infinity
}
{
Math.pow(0.7, 2) // 0.48999999999999994
const x = new BigNumber(0.7)
x.toPower(2) // '0.49'
new BigNumber(3).pow(-2) // '0.11111111111111111111'
}
示例3: BigNumber
import BigNumber from "bignumber.js";
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);