Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

toBigInt api? #18

Open
elee1766 opened this issue Nov 19, 2024 · 0 comments
Open

toBigInt api? #18

elee1766 opened this issue Nov 19, 2024 · 0 comments

Comments

@elee1766
Copy link

elee1766 commented Nov 19, 2024

i use dnum to go from token amount in decimals -> absolute token amount.

this is usually done by doing something like

const n = dnum.multiply(dnum.from(decimalAmount), 10n ** BigInt(decimals))

then i need to get the floor of this number as a bigint, to pass to viem, so i do

const bigIntValue = n[0] / 10n ** BigInt(n[1])

it would be useful if there was perhaps an api like.

toBigInt(n:Numberish): bigint


// usage:
const bigIntValue = dnum.toBigInt(n)

would you be open to a PR with something like this? or is there an existing function that i can use to do the same task?

dnum.from(n, 0)[0] maybe? (it seems sort of cursed)

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant