# Converting tokens with different decimal places

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. Dec 18, 2018 at 7:36

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.

• Not sure if this conversion is necessary if you always convert the smallest amount of each token (TokenBits) to each other.
– Yar
May 9 at 17:46