I was wondering how I can convert a specific amount of tokens, that have 6 decimals into a readable Integer with 2 decimals places. I know how to do it with tokens with 18 decimals by using the following line of code :

// 18 decimals token
const tokenAmountInWei = 10000000000000000000
const tokenAmount = await we3.utils.fromWei(tokenAmountInWei, "ethers");

How about an amount of token with 6 decimals?


1 Answer 1

const tokenAmountwDecimals = 10000000
const numDecimals = 6 
const tokenAmount = tokenAmountwDecimals / numDecimals

Just divide it by the right number of decimals! You'll have to use a bigNumber library if you have too many decimals or the number gets too big

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.