web3.js icon indicating copy to clipboard operation
web3.js copied to clipboard

Web3 1.0 Breaks BigNumbers

Open dskvr opened this issue 9 years ago • 3 comments

It appears that the new web3.utils.toBN does not return a true BigNumber object. It's missing a number of it's most critical functions, including but not limited to

toFixed() toFormat()

I confirmed this by including BigNumbers.js separately, creating a new BigNumber() from web3's BigNumber object, and then calling toFixed() (it worked). If this was intentional, it should be noted somewhere.

dskvr avatar Sep 04 '17 17:09 dskvr

Having same issue. let tokens = web3.utils.toBN(result).toString()

image

TheRyanHickman avatar Jan 31 '18 20:01 TheRyanHickman

+1 on this. If you look at the library used, https://github.com/SilentCicero/number-to-bn, it says in the README that decimals aren't supported...

A simple method to convert integer or hex integer numbers to BN.js object instances. Does not supprot decimal numbers.

console.log(numberToBN('0.9')); // or {}, [], undefined, 9.9

// throws new Error(...)

li-dennis avatar Feb 16 '18 06:02 li-dennis

We have started a discussion here about the future of big numbers and Web3.js.

nivida avatar Feb 27 '19 16:02 nivida