0

This question already has an answer here:

I am reading about ethereum (from technology stand point). I want to create an ICO smart contract (a typical ERC20 test token) where say if someone sends 0.1 ether to the contract address then they receive 10000 test tokens. However, can the receiving value (ie. 10000) be in fractions/floats like 1000.4500000000. I have read that EVM does not support floats. Is there a work around. Please assist

marked as duplicate by Ismael, Roman Frolov, Richard Horrocks, flygoing, Thomas Clowes Jan 4 '18 at 16:00

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

0

Generally, you just used fixed point arithmetic. In short, if you want to be able to send numbers with two decimal places, just multiply all the token values by 100 (and divide all the prices by 100). This is the purpose of the decimals variable in the token contracts here: https://ethereum.org/token.

For ether itself, numbers are always expressed in wei. 0.1 ether, for example, is 100000000000000000 wei.

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