Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Jan 13, 2021

Conversation

mrkn
Copy link
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
Development

Successfully merging this pull request may close these issues.

[Bug-13331] Inconsistent conversion of Float into Decimal
1 participant