Wolfram Research

Function Repository Resource:

RoundAwayFromZero

Source Notebook

Round a number away from zero

Contributed by: Sander Huisman

ResourceFunction["RoundAwayFromZero"][n]

rounds n away from 0.

ResourceFunction["RoundAwayFromZero"][n,a]

rounds n away 0 but to a multiple of a.

Examples

Basic Examples (2) 

Round a number:

In[1]:=
ResourceFunction["RoundAwayFromZero"][3.14]
Out[1]=

Round a negative number:

In[2]:=
ResourceFunction["RoundAwayFromZero"][-3.14]
Out[2]=

Scope (2) 

RoundTowardsZero is Listable:

In[3]:=
ResourceFunction["RoundAwayFromZero"][{-8.8, 4.1, 2.3, 2.9}]
Out[3]=

Round 'outwards' to a multiple of 0.25:

In[4]:=
ResourceFunction["RoundAwayFromZero"][{-8.8, 4.1, 2.3, 2.9}, 0.25]
Out[4]=

Properties and Relations (1) 

The opposite (rounding towards zero) can be achieved using IntegerPart:

In[5]:=
TableForm[
 Table[{i, ResourceFunction["RoundAwayFromZero"][i], IntegerPart[i]}, {i, {-8.8, 4.1, 2.3, 2.9}}], TableHeadings -> {None, {"Number", "Rounding away from zero", "IntegerPart"}}]
Out[5]=

Neat Examples

In[6]:=
Plot[ResourceFunction["RoundAwayFromZero"][x], {x, -3, 3}]
Out[6]=

Publisher

SHuisman

Version History

  • 1.0.0 – 12 September 2022

Related Resources

License Information