Number.RoundAwayFromZero
NumberRounds a number to the specified number of decimal places, always rounding away from zero on ties (the traditional "round half up" rule for positives).
Syntax
Number.RoundAwayFromZero(number as nullable number, optional digits as nullable number) as nullable numberParameters
| Name | Type | Required | Description |
|---|---|---|---|
number | number | Yes | The number to round. |
digits | number | No | The number of decimal places to round to. Defaults to 0 (nearest integer). |
Return Value
number — The number rounded away from zero to the specified decimal places.
Remarks
Number.RoundAwayFromZero implements "Round Half Away From Zero" — when a value falls exactly halfway between two representable values, it rounds to the value that is farther from zero. For positive numbers this means rounding up (2.5 → 3); for negative numbers this means rounding down toward more negative values (-2.5 → -3).
This is the conventional rounding taught in most schools and used in Excel's ROUND function. It is a useful alternative to Number.Round, which defaults to "Round Half to Even" (banker's rounding), where ties round to the nearest even number (2.5 → 2, 3.5 → 4). Banker's rounding is statistically unbiased over large datasets, but Number.RoundAwayFromZero matches common human expectations and matches Excel's behavior.
The optional digits parameter specifies how many decimal places to retain. When omitted, it rounds to the nearest integer. Negative values are not supported for digits.
When to use each:
- Use Number.RoundAwayFromZero when matching Excel, matching user expectations, or when presenting rounded values to end users
- Use Number.Round (banker's rounding) when statistically unbiased rounding is required for large financial datasets
Examples
Example 1: Positive half-value rounds up (away from zero)
Result | |
|---|---|
| 1 | 3 |
Example 2: Negative half-value rounds down (away from zero, toward -∞)
Number.RoundAwayFromZero(-2.5)Result | |
|---|---|
| 1 | -3 |
Example 4: Compare banker's rounding vs. away-from-zero on half-values
#table(
{"Value", "Number.Round (Banker's)", "RoundAwayFromZero"},
{
{0.5, Number.Round(0.5), Number.RoundAwayFromZero(0.5)},
{1.5, Number.Round(1.5), Number.RoundAwayFromZero(1.5)},
{2.5, Number.Round(2.5), Number.RoundAwayFromZero(2.5)},
{3.5, Number.Round(3.5), Number.RoundAwayFromZero(3.5)}
}
)Value | Number.Round (Banker's) | RoundAwayFromZero | |
|---|---|---|---|
| 1 | 0.50 | 0 | 1 |
| 2 | 1.50 | 2 | 2 |
| 3 | 2.50 | 2 | 3 |
| 4 | 3.50 | 4 | 4 |