简体   繁体   English

是否有返回 BigNumber.js 中字符数的 function?

[英]Is there a function that returns the number of characters in BigNumber.js?

I know about decimalPlaces :我知道decimalPlaces

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

And precision :精度

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

But I couldn't find any function that returns only the number of characteristics.但我找不到任何只返回特征数量的 function 。 That is, in this example, 3 ("1", "0" and "0").即,在本例中为 3(“1”、“0”和“0”)。

Is there something for this?有什么东西吗?

It seems there isn't one, as of Nov 2019 at least, but you can subtract the decimal places from the total precision to get the digits before the dot:至少截至 2019 年 11 月,似乎没有一个,但您可以从总精度中减去小数位以获得点之前的数字:

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

Note that:注意:

If d (the first parameter of the precision function) is true then any trailing zeros of the integer part of a number are counted as significant digits, otherwise they are not.如果dprecision函数的第一个参数)为真,则数字的 integer 部分的任何尾随零都计为有效数字,否则不计为有效数字。

See the docs:请参阅文档:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Bignumber.js shiftBy() 不是 function - Bignumber.js shiftedBy() is not a function 尝试使用bignumber.js处理大数 - Trying to handle big numbers with bignumber.js 了解bignumber.js库的局限性 - Understanding the limitations of the bignumber.js library (bignumber.js)“decimalPlaces”或“dp”不起作用 - (bignumber.js) "decimalPlaces" or "dp" not working bignumber.js中的`c`,`e`和`s`是什么意思? - What is the meaning of `c`, `e`, and `s` in bignumber.js? 从jsfromhell下载的bignumber.js javascript库的除法运算结果错误? - wrong result in division operation of bignumber.js javascript library downloaded from jsfromhell? BigNumber.js 计算在 C# 中使用十进制数据类型完成相同计算时显示不同的值 - BigNumber.js calculation shows different value when done same calculation in C# using decimal datatype require('bignumber.js')在松露测试中失败,npm ls -g显示已安装(Windows) - require('bignumber.js') fails in truffle test, npm ls -g shows it's installed (Windows) 使用带有加密货币价格的 BigNumber.js 进行的计算通常会返回科学计数法值 - calculations using BigNumber.js with cryptocurrency prices often return scientific notation values web3 错误:BigNumber 错误:“new BigNumber() 不是基数为 16 的数字:” - web3 error: BigNumber Error: "new BigNumber() not a base 16 number: "
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM