Skip to content

Fix round(n, :up) returning 0 for some nonzero values - #574

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

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

Conversation

@wtn

@wtn wtn commented Nov 14, 2026 •

Copy link
Copy Markdown
BigDecimal("1e-10").round(0, :up) # => 0 (expected 1)
BigDecimal("5").round(-10, :up)   # => 0 (expected 10000000000)
BigDecimal("1e-5").round(0, :up)  # => 1 (already correct)

BigDecimal stores digits in groups of nine and skips leading all-zero groups, so the first group of 1e-10 begins at the 10th decimal place. When the rounding position fell before the first group, :up truncated to 0.

BigDecimal stores digits in groups of nine and skips leading all-zero
groups, so the first group of 1e-10 begins at the 10th decimal place.
When the rounding position fell before the first group, :up truncated
to 0: BigDecimal("1e-10").round(0, :up) returned 0 instead of 1.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
@wtn wtn changed the title Fix ROUND_UP returning zero when rounding far left of the digits Fix round(n, :up) returning 0 for some nonzero values Nov 14, 2026

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