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

NumberHelper: handle objects responding to_d #49576

Merged
merged 1 commit into from Oct 11, 2023

Conversation

fatkodima
Copy link
Member

Fixes #49572.

Similar problem was also reported here - https://github.com/rails/rails/pull/49466/files#r1349249299.

Regression was introduced in #49466. Before that PR, numbers were checked via Float() method https://github.com/rails/rails/pull/49466/files#diff-f242a68844d34525bd9a0e26473578dfb8490bea375bf0c2cbb1a4e7f40cefadL177, which calls to_f on its arguments (see https://ruby-doc.org/core-3.1.1/Kernel.html#method-i-Float). to_f is defined on Money - https://github.com/RubyMoney/money/blob/ccddfdc9616b3f825578d66a50e718a318221cbc/lib/money/money.rb#L485-L487

But after, BigDecimal() is used which does not call any of these. So I left BigDecimal() for strings only, as these are not fully converted as needed when using to_f (https://ruby-doc.org/stdlib-3.1.1/libdoc/bigdecimal/rdoc/String.html#method-i-to_d), only leading characters. And called to_d for everything else. to_d is also defined for Money https://github.com/RubyMoney/money/blob/ccddfdc9616b3f825578d66a50e718a318221cbc/lib/money/money.rb#L462-L464.

@kamipo kamipo merged commit e8cad01 into rails:main Oct 11, 2023
4 checks passed
kamipo added a commit that referenced this pull request Oct 11, 2023
`NumberHelper`: handle objects responding `to_d`
@fatkodima fatkodima deleted the fix-number-helper-to_d branch October 11, 2023 08:50
@fatkodima
Copy link
Member Author

@kamipo Please do not forget to backport this to 7-0-stable too.

kamipo added a commit that referenced this pull request Oct 11, 2023
`NumberHelper`: handle objects responding `to_d`
@kamipo
Copy link
Member

kamipo commented Oct 11, 2023

Backported to 7-0-stable 72656c5.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ActionView 7.1.0 number_to_currency Not Returning Delimiter Of "," For USD Money Object
2 participants