In this track: Build, test and reason
advanced · 4 MIN READ

Test token decimals

Keep raw integers and display scaling separate.

LET’S PICTURE IT

Changing the ruler should not change the measured quantity.

SEE IT FOR YOURSELF
The same native ether amount shown as ETH, Gwei and WeiETH1× 1 billionGWEI1000000000× 1 billionWEI1000000000000000000

1 ETH = 1000000000 Gwei = 1000000000000000000 Wei.

Same value · different units · native ether only

Specify the unit model

A token with six decimals displays one token for raw value 1,000,000. A token with eighteen decimals uses a different scaling factor for the same displayed quantity.

Use exact arithmetic

Test integer or exact decimal-string conversions. Floating-point numbers can lose precision before a large raw amount reaches the encoder or assertion.

Exercise invalid precision

A six-decimal parser should reject a value requiring a seventh fractional digit unless the application explicitly defines a rounding policy.

Do not assume metadata always exists

ERC-20 decimals is optional metadata under the standard. An integration must define how missing or unexpected metadata is handled.

Define the test

decimals 6: parse("1") = 1000000
decimals 18: parse("1") = 1000000000000000000
reject unsupported fractional precision

Test plans are framework-neutral unless labeled as complete Solidity or JavaScript. Use a local test environment and no real funds.

TURN UNDERSTANDING INTO PRACTICEOpen the Wei / Gwei / ETH →
QUICK CHECK · NO PRESSURE

Does raw amount 1,000,000 always mean one token?

Your progress stays in this browser.
Keep exploring the original referenceethereum.org ↗

Original explanations by EtherTools. Examples are educational and source-linked; this site is independent of the Ethereum Foundation. Our approach.