Skip to content

Round whole numbers and numeric strings in ROUND - #374

Merged
joaothallis merged 1 commit into
developfrom
round-accepts-whole-numbers
Sep 21, 2026
Merged

joaothallis merged 1 commit into
developfrom
round-accepts-whole-numbers

Conversation

@joaothallis

@joaothallis joaothallis commented Sep 21, 2026

Copy link
Copy Markdown
Contributor

Why

ROUND only accepts a float, so ROUND(5), ROUND(2 * 3) or a variable holding a whole number raise a FunctionClauseError that crashes the caller.

What

ROUND now coerces its value the way FIXED does: whole numbers and numeric strings round, and anything else raises "expression is not a number".

`ROUND` piped its argument straight into `Decimal.from_float/1`, which only
accepts a float. So `ROUND(5)`, `ROUND(2 * 3)` and a variable holding a whole
number all raised a `FunctionClauseError`, while the same expression with a
fractional value worked. That error is not one `evaluate_block!/4` converts into
an `Expression.Error`, so it crashed the caller.

Coerce the value with the helper `FIXED` already uses, then build the decimal
from either an integer or a float. A whole number now rounds to itself, a numeric
string rounds like the number it holds, and a value that is not a number raises
the standard "expression is not a number" error.

Release as 3.0.0-rc.5.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@joaothallis joaothallis self-assigned this Sep 21, 2026
@joaothallis
joaothallis marked this pull request as ready for review September 21, 2026 14:50
@joaothallis
joaothallis merged commit 8c7b9c0 into develop Sep 21, 2026
2 checks passed
@joaothallis
joaothallis deleted the round-accepts-whole-numbers branch September 21, 2026 15:02
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.

2 participants