Skip to content

fix: preserve exact decimal scales in token unit conversion - #1334

Open
piguagua wants to merge 1 commit into
rocket-pool:masterfrom
piguagua:my_feature
Open

piguagua wants to merge 1 commit into
rocket-pool:masterfrom
piguagua:my_feature

Conversation

@piguagua

@piguagua piguagua commented Nov 8, 2026

Copy link
Copy Markdown

EthToWeiWithDecimals constructs 10^decimals as a float64 before multiplying. For decimals such as 24 and 36, the scale is already rounded and even an amount of 1 produces the wrong integer. Parse the existing decimal representation as a rational, multiply by an exact integer power of ten, and divide with truncation toward zero.

The table covers high decimal counts, fractional amounts, negative values and truncation. go test ./shared/math -count=1 passed. The input remains float64; this patch does not recover precision already lost by callers.

Signed-off-by: piguagua <shabipengqi@outlook.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant