Skip to content

Allow digits=0 in BigDecimal(flt) and Float#to_d#180

Merged
mrkn merged 1 commit intomasterfrom
fix_float_to_bigdecimal_conversion
Jan 13, 2021
Merged

Allow digits=0 in BigDecimal(flt) and Float#to_d#180
mrkn merged 1 commit intomasterfrom
fix_float_to_bigdecimal_conversion

Conversation

@mrkn
Copy link
Copy Markdown
Member

@mrkn mrkn commented Jan 13, 2021

Using dtoa of mode=0, we can determine the number of digits in decimal that is
necessary to represent the given Float number without errors.

This change permits digits=0 in BigDecimal(flt) and Float#to_d, and these
methods use dtoa of mode=0 when the given digits is 0.

Internal implicit conversion from Float also uses digits=0.

[Fix GH-70]

Using dtoa of mode=0, we can determine the number of digits in decimal that is
necessary to represent the given Float number without errors.

This change permits digits=0 in BigDecimal(flt) and Float#to_d, and these
methods use dtoa of mode=0 when the given digits is 0.

Internal implicit conversion from Float also uses digits=0.

[Fix GH-70]
@mrkn mrkn merged commit 2dbe170 into master Jan 13, 2021
@mrkn mrkn deleted the fix_float_to_bigdecimal_conversion branch September 21, 2021 05:59
yahonda added a commit to yahonda/rails that referenced this pull request Sep 5, 2023
To prepare Ruby 3.4 will ship `bigdecimal` as bundled gem,
`bigdecimal` has been added to Active Support runtime dependency
via rails#49039

It will install BigDecimal version 3.1.4 or higher,
so we just check the BigDecimal 3.1+ behavior at `NumericalityValidationTest`.

Refer to
rails#49039
ruby/bigdecimal#180
ruby/bigdecimal#70
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.

[Bug-13331] Inconsistent conversion of Float into Decimal

1 participant