1

Hi let's say I have a smart-contract that converts one erc20 for another erc20.

erc20A is set up with 18 decimals

erc20B is set up with 6 decimals

i want to convert 10 erc20A tokens to 10 erc20B tokens, and keep them in their respected format.

  • Show your code, it's hard to refer to your question otherwise. – goodvibration Dec 18 '18 at 7:36
1

The number of decimals in ERC20 determines the factor used to represent the decimal number as uint. For instance 18 means that the value is stored in an uint as decimalValue * 10**18.

For instance: 100,103 => is stored as uint 100103000000000000000

If you want to convert between different representations you have to multiply or divide depending on the difference in decimals count:

valueB = valueA / (10**(18-6))
valueA = valueB * (10**(18-6))

Of course, division will lead to precision loss.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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