Solidity Token Contract – No Float vs Decimal Places Requirement

go-ethereumsoliditytokens

We know that solidity doesn't support the float values. But here (https://www.ethereum.org/token#understanding-the-code) they accept one input parameter 'decimal places' for calculation purpose. How this action has been executed when this token is created using the contract written using solidity?

Best Answer

What is actually happening in sub-dividable token contracts (and ETH itself) is that the actual unit is tiny. Really, really tiny. A single ether is actually just 10^18 wei. For the sake of the users, it's shown on the various frontends as a decimal number of ETH.

The same principle applies in token contracts. Internally it's just a standard uint holding gargantuan numbers, but when displayed it's converted by the frontend into a small, human-readable number.

This is so that the token can be divided in nearly any amount, and if it suddenly needs to be divided even more then all it takes is adjusting the frontend to handle it.

Related Topic