是否有一个函数返回BigNumber.js中的字符数?

问题描述 投票:-1回答:1

我知道decimalPlaces

const number = new BigNumber(100.5254);
number.decimalPlaces(); // 4

precision

const number = new BigNumber(100.5254);
number.precision(); // 7

但是我找不到任何仅返回特征数的函数。也就是说,在此示例中,为3(“ 1”,“ 0”和“ 0”)。

有东西吗?

javascript digits bignum
1个回答
0
投票

[似乎至少没有一个,至少到2019年11月为止,但是您可以从总精度中减去小数位以获得小数点前的数字:

const number = new BigNumber(100.5254);
const digitsBeforeDot = number.precision(true) - number.decimalPlaces();
// prints 3

注意:

如果dprecision函数的第一个参数)为true,则数字整数部分的任何尾随零都将被视为有效数字,否则将不被视为有效数字。

请参阅文档:

© www.soinside.com 2019 - 2024. All rights reserved.