Skip to content

fix: coerce double to decimal via str() to avoid IEEE 754 expansion#3928

Open
AnnasMazhar wants to merge 1 commit intodlt-hub:develfrom
AnnasMazhar:fix/3917-decimal-coerce-float-str
Open

fix: coerce double to decimal via str() to avoid IEEE 754 expansion#3928
AnnasMazhar wants to merge 1 commit intodlt-hub:develfrom
AnnasMazhar:fix/3917-decimal-coerce-float-str

Conversation

@AnnasMazhar
Copy link
Copy Markdown

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

…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.
@AnnasMazhar AnnasMazhar marked this pull request as ready for review May 9, 2026 14:19
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.

Coercion from double to decimal can produce unexpected values

1 participant