Tech
Why Decimal Can Round a UInt256 Token Amount, and an Exact Alternative
The documented raw balance is a UInt256String: an unsigned integer string that can reach 78 digits. When you display one in Python, Decimal looks like the obvious tool. The trap is subtle: building a Decimal from a string is exact, but arithmetic on it can round.
Where the rounding happens
Decimal(raw) keeps every digit, because construction ignores the context precision. Operations such as scaleb , normalize , multiplication, or division round their result to the context...
Read the full discussion on Dev.to
This article was aggregated from Dev.to. Click to join the conversation.
View on Dev.to