-2

Unable to understand why Block chain uses before decimal point uses 8 zeros. As far as ETH its Giga Wei and satoshi for bitcoin. But why we use so many zeros?

1
  • Without context of you telling where did you obtain this number, it is impossible to tell why your particular number has eight zeroes. Commented Jul 31, 2022 at 3:57

1 Answer 1

1

Representing floating point numbers and doing float arithmetic in code is funky. We prefer to use integers (in solidity's case, unsigned 256 bit integers, uint256).

As such, 1 unit of value in Ethereum (for example, msg.value==1 in the context of a transaction) in reality represents the smallest amount of Ethereum available for calculation: 1 wei, or 10^(-18) Ethers.

To help with arithmetic, solidity also employs helpers as global variables, such as:

msg.value = 1 wei; //This is 1:1 with what I just described
msg.value = 2 gwei //This is equivalent to 2 * 1e9 weis
msg.value = 3 ether // This is equivalent to 3 * 1e18 weis, 3 full ethers

You can read up more on it, as well as the philosophy behind it, in the solidity docs here: https://docs.soliditylang.org/en/v0.8.14/units-and-global-variables.html

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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