gpt4 book ai didi

javascript - 除大数时有没有办法得到更精确的结果?

转载 作者:行者123 更新时间:2023-11-30 09:16:03 26 4
gpt4 key购买 nike

我需要对 Big Numbers 进行操作,但我需要结果准确,如下所示:

const BN = require('bn.js');
var a = 11060622312717714974
var b = 1570481433500000000000;
console.log(a/b); //0.0070428227146040415

当我使用 Big Number 时,我只得到 0,没有精度:

var aBN = new BN('11060622312717714974');
var bBN = new BN('1570481433500000000000');
console.log(aBN.div(bBN).toString()); //0

用这个库能得到精确的结果吗?

最佳答案

不熟悉这个库,但是看了一下 README.md 文件,它说:

Note: decimals are not supported in this library.

因此,据此,答案是否定的。

参见 https://github.com/indutny/bn.js/#usage .

关于javascript - 除大数时有没有办法得到更精确的结果?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55031164/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com