If you have a BigNumber when using web3, then you can convert this to a regular Javascript Number using the ethers library as follows:

ethers.BigNumber.from(max).toNumber()

<a href="https://github.com/ethers-io/ethers.js/" target="_blank" rel="noreferrer noopener nofollow">Ethers</a> is a complete Ethereum library and wallet implementation in Javascript.

I ran into this when reading token balances from a smart contract — the values come back as BigNumber objects and you can’t do normal math on them directly. The .toNumber() method works fine for values that fit in a JavaScript safe integer (up to 2^53). For larger values like wei amounts, use .toString() instead to avoid precision loss. In ethers v6, the BigNumber class was replaced with native BigInt, so the syntax changes to BigInt(value) if you’re on the latest version.