You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The parse_value function currently converts the input using _Decimal(value). When a float is passed as input, this conversion may lead to precision loss due to the inherent imprecision of floating-point representations.
Steps to Reproduce
Call Decimal.parse_value(0.01).
Observe that the resulting Decimal does not accurately represent the value 0.01 instead gives0.01000000000000000020816681711721685132943093776702880859375 which is inaccurate.
Expected Behavior
The function should convert the input to a string before creating the Decimal object (i.e., using _Decimal(str(value))). This approach ensures that decimal values are accurately converted, even if not provided as string, preserving their intended precision.
mak626
changed the title
Inaccurate Float-to-Decimal Conversion in parse_value of Decimal scalar
Inaccurate Float-to-Decimal Conversion in parse_value of DecimalScalarFeb 10, 2025
Current Behavior
The
parse_value
function currently converts the input using_Decimal(value)
. When a float is passed as input, this conversion may lead to precision loss due to the inherent imprecision of floating-point representations.Steps to Reproduce
Decimal.parse_value(0.01)
.Decimal
does not accurately represent the value0.01
instead gives0.01000000000000000020816681711721685132943093776702880859375
which is inaccurate.Expected Behavior
The function should convert the input to a string before creating the
Decimal
object (i.e., using_Decimal(str(value))
). This approach ensures that decimal values are accurately converted, even if not provided as string, preserving their intended precision.see Strawberry implementation
Suggested Fix
Modify the
parse_value
function as follows:The text was updated successfully, but these errors were encountered: