Why ether has subunits
Ethereum's native asset is divisible to 18 decimal places, and the EVM does all arithmetic in the smallest unit — wei — as unsigned 256-bit integers. Floating-point ether is a bug factory: 0.1 + 0.2 !== 0.3 in IEEE-754, and rounding at the 18th decimal loses real money at scale. The rule: store and compute in wei, format for humans only at the edges.
The unit ladder
| Unit | Wei | Typical use |
|---|---|---|
| wei | 1 | EVM arithmetic, balances |
| Kwei | 103 | rarely used |
| Mwei | 106 | rarely used |
| gwei | 109 | gas prices |
| microether | 1012 | rarely used |
| milliether | 1015 | rarely used |
| ether | 1018 | human amounts |
Gas math you'll do weekly
Transaction cost = gas used × gas price (in gwei), paid in ether. A swap using 180,000 gas at 12 gwei costs 180,000 × 12 gwei = 2,160,000 gwei = 0.00216 ETH. Since EIP-1559, "gas price" splits into a base fee (burned) plus a priority tip; wallets quote maxFeePerGas and refund the difference.
Pitfalls that cost money
- JavaScript numbers top out at 253 — about 9 ETH in wei. Always use BigInt (
1000000000000000000n) or a decimal library;Number("3 ETH in wei")silently loses precision. - Decimals differ per token. ERC-20 tokens choose their own — USDC uses 6, most others 18. Reading
balanceOfwithout dividing by the token's decimals gives answers 1012× off. - Formatting: display with fixed decimals and explicit rounding — trailing-zero trimming can hide rounding that shortchanges users.
Convert wei/gwei/ether exactly, with BigInt precision, using the EVM Unit Converter — no floating-point traps.