本文整理汇总了TypeScript中bignumber.js.default.comparedTo方法的典型用法代码示例。如果您正苦于以下问题:TypeScript js.default.comparedTo方法的具体用法?TypeScript js.default.comparedTo怎么用?TypeScript js.default.comparedTo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类bignumber.js.default
的用法示例。
在下文中一共展示了js.default.comparedTo方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: BigNumber
const x = new BigNumber(-0.8)
const y = x.absoluteValue() // '0.8'
const z = y.abs() // '0.8'
}
{
const x = new BigNumber(1.3)
x.ceil() // '2'
const y = new BigNumber(-1.8)
y.ceil() // '-1'
}
{
const x = new BigNumber(Infinity)
const y = new BigNumber(5)
x.comparedTo(y) // 1
x.comparedTo(x.minus(1)) // 0
y.cmp(NaN) // null
y.cmp('110', 2) // -1
}
{
const x = new BigNumber(123.45)
x.decimalPlaces() // 2
const y = new BigNumber('9.9e-101')
y.dp() // 102
}
{
const x = new BigNumber(355)
const y = new BigNumber(113)
示例2: percentageDiff
* Calculate the percentage difference
* between
*
* @param {string|BigNumber} newNum The new number
* @param {string|BigNumber} oldNum The old number
* @returns {{ diff: string; increase: boolean }}
*/
percentageDiff(
newNum: string | BigNumber,
oldNum: string | BigNumber,
): { diff: string; increase: boolean } {
const newNumBig = new BigNumber(newNum);
const oldNumBig = new BigNumber(oldNum);
if (newNumBig.eq(oldNumBig)) {
return { diff: "0", increase: false };
} else if (newNumBig.comparedTo(oldNumBig) > 0) {
const inc = newNumBig.minus(oldNumBig);
return {
increase: true,
diff: inc
.div(oldNumBig)
.times(100)
.toString(),
};
} else {
const dec = oldNumBig.minus(newNumBig);
return {
increase: false,
diff: dec
.div(oldNumBig)
.times(100)