Skip to content

Keep the sign in BigDecimal#to_digits for values in (-1, 0) - #573

Open
wtn wants to merge 1 commit into
ruby:masterfrom
wtn:digits
Open

wtn wants to merge 1 commit into
ruby:masterfrom
wtn:digits

Conversation

@wtn

@wtn wtn commented Nov 14, 2026

Copy link
Copy Markdown
BigDecimal("-0.5").to_digits # => "0.5" (expected "-0.5")

The integer part came from to_i.to_s, which is "0" for these values. to_digits is documented as deprecated in favor of to_s("F"), so it now returns to_s("F"). Output is otherwise unchanged.

to_digits built the integer part from to_i.to_s, which is "0" for any
value between -1 and 0, so the minus sign was lost:
BigDecimal("-0.5").to_digits returned "0.5". to_digits is
documented as deprecated in favor of to_s("F"), so it now returns
to_s("F").

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
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.

1 participant