1

I want to set my price of token sale in ICO as 1 ether=0.0111111111. Since, solidity doesn't support decimals, what is suggested way to do that?

0

3 Answers 3

2

There are several ways to to this:

  1. Use simple fractions. Your rate is 1/90, right? So just multiply or divide by 90 to convert from ether to tokens and vice versa.

  2. Use binary fixed point (e.g. via ABDKMath64x64 library). Basically this is simple fractions with constant denominator 2^64.

  3. Use decimal fixed point with, say, 18 decimals (e.g. via DBMath library). So your rate will be represented by number 11111111100000000. Basically this is simple fractions with constant denominator 10^18.

  4. Use floating point numbers (e.g. via ABDKMathQuad library).

What option is the best depends on your range/precision/price requirements, and on what math you need to do with the rate.

1

Assuming that you are deploying an ERC20 token, you can achieve your goal by setting decimal. Let's say you have 100 merbles which do not exist expect yours in the world, and you want to sell each merble as bonds to 1000 people. If you set decimal to 3, 100 * 10^3(Corresponding 1000 people) supply is required for your token sale. The smallest unit of your token will be 0.001. In crowdsale, you can announce 0.001 MerbleCoin(MRB) will be 1 ether. Ethereum support up to 18 decimals, but in our case you do not need more than 3. If you want to achieve 0.0111111111, you are required to set decimals as 10.

0

Add zeros and converts your decimal to an integer. all calculation will be done outside of the smart contract. like if 1 ether = 4.589 token; multiply the token value by 1000 and it would become an integer 4589. that's why we always multiply the total token amount with the number of decimal points we want to put inside smart contract

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