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

Add .to_s('F') digit grouping for integer part #264

Merged
merged 2 commits into from Jul 5, 2023
Merged

Add .to_s('F') digit grouping for integer part #264

merged 2 commits into from Jul 5, 2023

Conversation

cryptogopher
Copy link

@cryptogopher cryptogopher commented Jul 1, 2023

Right now to_s('F') digit grouping works properly only for fractional part. For integer part result is unspecified. In reality we also get grouping, but of unpractical nature:

# ruby -e "require 'bigdecimal'; puts BigDecimal('1234567.1234567').to_s('3F')"
123 456 7.123 456 7

This patch fixes grouping of integer part:

# ruby -e "require 'bigdecimal'; puts BigDecimal('1234567.1234567').to_s('3F')"
1 234 567.123 456 7

I consider this change backwards compatible as:
a) docs say only about grouping fractional part, no declarations about grouping integer part,
b) total string length without changes,
c) integer part grouping didn't make sense so there should be no or not much real life dependencies.

Also added some tests.

@mrkn mrkn self-requested a review July 5, 2023 20:00
@mrkn mrkn merged commit 8a94a29 into ruby:master Jul 5, 2023
51 checks passed
@zzak
Copy link
Member

zzak commented Jul 8, 2023

Looks like this broke some Active Support tests:
rails/rails#48693

@nobu
Copy link
Member

nobu commented Jul 8, 2023

This change does not related to ruby versions.
Before bad habit that testing this by RUBY_VERSION will spread more, we should bump up BigDecimal::VERSION.

@nobu nobu mentioned this pull request Jul 8, 2023
zzak added a commit to zzak/rails that referenced this pull request Jul 9, 2023
The previous examples were causing failures in CI, after ruby/bigdecimal#264 was merged.

For example:

```
Failure:
NumericExtFormattingTest#test_default_to_fs [/rails/activesupport/test/core_ext/numeric_ext_test.rb:446]:
--- expected
+++ actual
@@ -1 +1,3 @@
-"10000 10.0"
+# encoding: US-ASCII
+#    valid: true
+"10 00010.0"
```

The recommendation was to adjust the test to deal with the upstream change more flexibly.
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.

None yet

4 participants