Converts wei value into a ether value for decimals 9

I Want to Converts a wei value into a ether value for decimals 9 but i got wrong value.

Example:

https://bscscan.com/tx/0xe3a7061193482f5af33aadbb21804923d90e5c31a729d1c59da14ebd2f499873

In the Input Data we see amountOut: 500125000000000

This number after Converts to ether, must be amount of the Token or BNB .

But I get another amount.

I check for another Tokens (with another decimals), i got correct value.

Why ?

Im using this code for converts:

const tokenValue = Moralis.Units.FromWei("500125000000000", 9)

1 Like

it looks like that transaction converts BNB into a token with 9 decimal and Moralis.Units.FromWei("500125000000000", 9) give the right number in this case.

Please send the value

this is the value that I got: 500125

Right, but what is for value ?

it is the a value of this token: https://bscscan.com/token/0x2b3f34e9d4b127797ce6244ea341a83733ddd6e4 that has 9 decimals

Right, but in the bscscan the value of the coin shows: 485,121.25

https://bscscan.com/tx/0xe3a7061193482f5af33aadbb21804923d90e5c31a729d1c59da14ebd2f499873

Because you are comparing two different numbers.

You assume that amountOut (which is 500125000000000) is the amount the user gets in the end ( actually 485,121.25) but this is not the case.

2 Likes