fix: coerce double to decimal via str() to avoid IEEE 754 expansion#3928
Open
AnnasMazhar wants to merge 1 commit intodlt-hub:develfrom
Open
fix: coerce double to decimal via str() to avoid IEEE 754 expansion#3928AnnasMazhar wants to merge 1 commit intodlt-hub:develfrom
AnnasMazhar wants to merge 1 commit intodlt-hub:develfrom
Conversation
…sion
When coercing a double (float) to Decimal, passing the float directly
to Decimal() triggers the full IEEE 754 double-precision representation,
producing values like Decimal('34.70000000000000284...') for float 34.7.
Instead, use Decimal(str(value)) which preserves the human-readable
representation. This fixes schema evolution and data writes on strict
destinations like BigQuery that reject expanded decimal forms.
Same fix applied to the double→Wei coercion path, since Wei extends
Decimal.
Adds test verifying 34.7 → stays exactly 34.7 for both decimal and wei.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #3917
When coercing a double (float) to Decimal, passing the float directly
to Decimal() triggers the full IEEE 754 double-precision representation,
producing values like Decimal('34.70000000000000284...') for float 34.7.
Fix: coerce via Decimal(str(value)) instead, which preserves the
human-readable representation. Same fix applied to double→Wei coercion.
Added test: test_coerce_double_to_decimal_no_float_expansion