Home

roundawayfromzero

Round away from zero is a rounding mode used to convert a real number to an integer by increasing its magnitude away from zero. In this scheme, positive values are moved upward, negative values downward, and zero remains zero.

Formally, if x > 0 then round_away(x) = ceil(x); if x < 0 then round_away(x) = floor(x); if x = 0

Some uses describe a related variant as rounding to the nearest integer with ties broken away from

Round away from zero is distinct from round toward zero (which truncates toward zero) and from round

Implementation notes: in many languages you can implement as described above with existing ceiling and floor

then
0.
This
guarantees
that
nonzero
values
round
to
the
next
integer
in
their
sign
direction.
Examples:
3.2
becomes
4;
3.0
stays
3;
-2.8
becomes
-3;
-0.1
becomes
-1;
0
stays
0.
zero,
so
1.5
→
2
and
-1.5
→
-2.
to
nearest
(which
selects
the
closest
integer,
sometimes
with
different
tie
rules).
It
is
used
in
contexts
where
a
magnitude-preserving
step
is
required,
such
as
certain
numerical
methods,
graphics,
or
user-facing
interfaces
that
must
avoid
underestimating
a
magnitude.
functions:
if
x
>
0,
use
ceil(x);
if
x
<
0,
use
floor(x).
Be
mindful
of
floating-point
precision
near
integers
and
special
values
such
as
NaN
or
infinities,
which
should
be
handled
according
to
the
language's
rules.