像 Kotlin 一样将 BigNumber 转换为 Int

问题描述

我在 Kotlin 中有以下内容可以将 BigInteger 转换为普通的 integer

    val bigIntDiv = bigIntVal?.div(BigInteger.valueOf(429496))
    val resultInt = bigIntDiv?.toInt() //This line converts the big Interger down to regular integer

如何在 javascript 中实现相同的转换。

我正在使用 BigNumber.jshttps://github.com/MikeMcl/bignumber.js/,但我找不到从 BigNumber 中取回常规整数的方法

这是我目前拥有的 BigNumber.js 库:

let bigIntVal = new BigNumber("5ACDBB4CC493D909F423D779C2C55E7381DFAE6547DCEFE5712F",16)

现在我想取回上面 Kotlin 等效代码中显示的常规整数?

这样:

let regularInteger = bigIntVal.toInt(); //would be the same value as returned from the Kotlin's end?

对于一个样本 bignumber

5.09632306328228901945340839021510597564609217303391975753746718457743300101444483767019949e

我尝试使用 BigNumber.js 库进行以下操作:

let initial = new BigNumber("5.09632306328228901945340839021510597564609217303391975753746718457743300101444483767019949e",16);
let workingVal = initial.toNumber(); //This gives 5.096323063282289e+70,which is not what I want

当我在 kotlin 中编写类似的代码时,kotlin 给了我想要的

    val resultInt = initial?.toInt() //Kotlin gave me -1879845894 which is great to work with.

那么,我如何使用 BigNumber.js 库实现相同的目标 谢谢。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)