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

BigRational#format is incorrect #14062

Closed
HertzDevil opened this issue Dec 7, 2023 · 0 comments · Fixed by #14525
Closed

BigRational#format is incorrect #14062

HertzDevil opened this issue Dec 7, 2023 · 0 comments · Fixed by #14525

Comments

@HertzDevil
Copy link
Contributor

BigRational#format treats the entire string from #to_s as an integer, and then applies thousands separators over that directly:

require "big"

BigRational.new(100, 3).format          # => "10,0/3"
BigRational.new(1234567, 890123).format # => "12,345,67/,890,123"

This is entirely wrong. We have two options:

  • Format the numerator and denominator separately, giving 100/3 and 1,234,567/890,123.
  • Delegate to #to_f, giving 33.33333333333333 and 1.386962251284373.

#humanize is not affected, since it calls #format via #to_f rather than directly.

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

Successfully merging a pull request may close this issue.

1 participant