What is the mathematical notation for rounding a given number to the nearest integer? So like a mix between the floor and the ceiling function.

6There are many common operations that do not have a widely agreed on standard notation. For various reasons, rounding is among them. In these cases you can use whatever notation you want. You just have to explain the notation when you introduce it. In this case, part of what you should explain is which rules of rounding you are using, as "nearest integer" is ambiguous when the value is halfway between two integers. Rounding $0.5$ up is commonly thought of, but causes bias when used on large datasets. Rounding $n.5$ to the nearest even integer is commonly used to avoid that bias. – Paul Sinclair Sep 12 '19 at 16:58

10I'm not a mathematician so I don't know what is common and won't post this as an answer but I think just writing $\lfloor x + 0.5\rfloor$ might work – Ivo Beckers Sep 13 '19 at 07:34

@Paul Sinclair, it depends on what statistic will have the bias. For a statistic that is the product of all the numbers, rounding 0.5 to the nearest even number would be absolute disaster. – richard1941 Sep 18 '19 at 02:36

@richard1941  You appear to have completely missed the point of my remark, which was to give an example of why "rounding to the nearest integer" is ambiguous, thus supporting the point that when discussing rounding, one should be clear about what rules you are following. Rounding to even is a very, very common practice in real world applications, which commonly sum large datasets, but almost never multiply them.. – Paul Sinclair Sep 18 '19 at 03:30

@Paul Sinclair. I apologize. Certainly a very, very common practice in the real world must be right. – richard1941 Sep 19 '19 at 05:47

@richard1941  "right'? Obviously you still haven't figured out what I am talking about. – Paul Sinclair Sep 19 '19 at 16:38
8 Answers
I have seen $\lfloor x \rceil$. It must have been in the context of math olympiads, so I can't point to a book that uses it. Wikipedia suggest this notation, among others: nearest integer function.
Personally, I would prefer $[x]$, being a cleaner mix of $\lfloor x \rfloor$ and $\lceil x \rceil$. But I've seen this notation being used for the floor function. Especially in older texts, say, preTeX era.
You could also do something like $\mathrm{nint}(x)$, but in formulas that could be cumbersome.
See also the remarks at Mathworld.
 24,846
 5
 45
 108

27Trouble with $[x]$ is that with any somewhatcomplicated expression in the middle it runs the risk of being confused with ordinary square brackets. – The_Sympathizer Sep 13 '19 at 00:47


3

1Isn't $[x]$ commonly used to represent the integer part of `x`, (i.e., round towards 0)? That's different from the usage proposed here if `x` is negative. – chepner Sep 14 '19 at 22:16

I cannot find such a notation on Wikipedia. Could anyone give a more precise link? Thanks! – Cm7F7Bb Feb 19 '20 at 22:50

1The article I linked to was merged into another in November, and things were lost in the process. It is still in the revision history: https://en.wikipedia.org/w/index.php?title=Nearest_integer_function&oldid=926348660 – Bart Michels Feb 20 '20 at 08:16

The similar notation $\lceil x\rfloor$ is used in pp. 43 and 260 of Flajolet and Sedgewick's *Analytic Combinatorics* (Cambridge University Press, 2009). – xFioraMstr18 Apr 15 '20 at 15:31
I have seen the notation $[x]$. However, that is some times used as the floor function when TeX is unavailable, or the author is unfamiliar with it (I'm sure there are plenty of examples on this site, for instance).
The safest bet is to say something along the lines of
Let $[x]$ mean the integer closest to $x$ (rounding up for halfinteger values).
or
Let $[\phantom x]$ denote the standard rounding function.
That is, explicitly defining the notation yourself, so that anyone who reads your text knows exactly what you're talking about. If you do this, you are of course entirely free to "invent" your own notation (within reason) for this if there is some other notation you prefer.
 187,016
 14
 158
 288

11Please, _please_ don't use simple square brackets for rounding. They are already used for far too many other things. – leftaroundabout Sep 13 '19 at 09:43

3@leftaroundabout That depends entirely on what you're currently doing. Most uses are limited to a specific field of study. Also, there are only so many readilyavailable notations one _can_ use, and square brackets get the job done. I have seen it used many times, and I have only gotten confused when they've been used to denote the _floor_ function without adequately clarifying that fact. – Arthur Sep 13 '19 at 10:11

5Please **never** use the "roundup for .5" rule. It introduces a bias in your data. Use the rule to round to the nearest even (or odd, doesn't really matter) integer. – Carl Witthoft Sep 13 '19 at 11:27

1@Arthur limited to a specific field or not, it's still better to avoid using the same notation for different purposes. Your writing may be _mostly_ intended for people from the same field, but you should still not make it more difficult than necessary for experts from other branches. That's especially true for something as hard to look up as some flavour of brackets. The exception is if you have lots and lots of these in your calculations and thus space is at a premium, but in that case $\lfloor\cdot\rceil$ is just as fine as $[\cdot]$. – leftaroundabout Sep 13 '19 at 11:53
Whatever notation you use (punctured dusk gives some good suggestions), you should always define this explicitly if you are going to use it, since there is no standard way to treat halfintegers. (I recently found this out the hard way when I assumed the rounding method I was always taught was standard, but python's default does something different.)
 37,348
 9
 46
 78

6In some implementations, $[1.5] = 1$ ("round exact halfintegers up") and in others, $[1.5] = 2$ ("round exact halfintegers away from zero") – Monty Harder Sep 12 '19 at 20:04

1And some implementations are not clear if they round _down_ or _towards zero_ for negative numbers. – KalleMP Sep 12 '19 at 20:56

7@MontyHarder There is also [Bankers Rounding is an algorithm for rounding quantities to integers, in which numbers which are equidistant from the two nearest integers are rounded to the nearest even integer.](http://wiki.c2.com/?BankersRounding) – Acccumulation Sep 12 '19 at 21:42

2Yes,"banker's rounding" is the default in recent versions of python. The difference between "towards infinity" and "away from zero" is less critical because in many cases you're working in a context where everything is nonnegative and can ignore that distinction. – Especially Lime Sep 13 '19 at 07:16

@MontyHarder: Both of those are bad (introduce bias). – R.. GitHub STOP HELPING ICE Sep 14 '19 at 16:26
Although I'm not sure how common this is in pure maths settings, I would say the best notation is simply $\operatorname{round}(x)$. This is easily understood, albeit not completely unambiguous – but definitely better than $[x]$ which could mean a myriad of completely unrelated things, or $\operatorname{nint}(x)$ which looks like “ninnt?”
If the ambiguity $1 \stackrel?= \operatorname{round}(1.5) \stackrel?= 2$ is a problem for you, make sure to explicitly discuss this. If you use the operation a lot, you could also define that you write it as $\lfloor x\rceil$, but I wouldn't use that without discussion.
round
is also the name for the rounding function in many programming languages, because what it does is it rounds a number, hence the name “round”.
 5,901
 23
 36

1I prefer this notation, *but* the ambiguity of "[round](https://en.wikipedia.org/wiki/Rounding)" is perhaps much greater than you suggest (and you have not minimized the ambiguity). I've worked with round up, round down, round towards zero, round away from zero, round half up, round half down, round half toward zero, round half away from zero, round half to even, round half to odd, round half alternating, round half randomly, round randomly, and many more variants. – Eric Towers Sep 13 '19 at 13:58
If you are fine going always in one direction for halfway values, you can resort to the programming trick of using $\lfloor x + \frac{1}{2} \rfloor$ (halfways towards $+\infty$) or $\lceil x  \frac{1}{2} \rceil$ (halfways towards $\infty$).
 348
 1
 10
I have seen $(\!(x)\!)$ for "nearest integer." My memory is dim, but maybe it was Emil Grosswald's elementary number theory text. I like it because it's easy to type and it's not likely to be confused with another function.
 7,857
 1
 15
 39
 29,599
 2
 22
 57
It might be too verbose, but something like the following is unlikely to be misinterpreted.
$$\mathrm{RoundToEven}(5.5) = 6$$
If you need another convention such as rounding to the nearest odd number, rounding towards infinity, or rounding towards negative infinity I'd define my own function and include some examples.
For instance:
Let $R \mathop: \mathbb{R} \to \mathbb{Z}$ denote the function that rounds each real number to the nearest integer, rounding ties towards negative infinity.
$$ R(0.5) = 1 $$ $$ \left\{ R(0.3)\;,\; R(0)\;,\; R(0.3)\;,\; R(0.5) \right\} = \left\{ 0 \right\} $$ $$ R(1.5) = 1 $$ $$ R(1.7) = 2 $$
 6,712
 3
 13
 29
The short and sweet is that there is no short and sweet. Rounding has many different contexts and interpretations, which means that you will have to define what rounding means to you in your particular context before your use it. Now, there is standard notation for two specific types of rounding. $\lceil\text{Ceiling}\rceil$ brackets indicate that you always round up toward positive infinity, e.g. $\lceil1.1\rceil = 2$ and $\lceil3.9\rceil = 3$, and $\lfloor\text{floor}\rfloor$ brackets indicate that you always round down toward negative infinity, e.g. $\lfloor2.9\rfloor=2$ and $\lfloor6.1\rfloor=7$.
Now, if we wish to define the typical elementary/secondary school form of rounding where you need to specify how many decimal places you wish to round to, and halves always gets rounded up, then we could do so as follows:
For $d \in \mathbb Z$, let $R_d:\mathbb R \rightarrow \mathbb Z$ such that $$R_d(x) = \frac{\lfloor10^d x + 0.5\rfloor}{10^d}$$
Note that this method creates a bias towards positive infinity and as such the rounding behavior for positive and negative numbers seems incongruous for some. In response to this, some elementary/secondary classes may then adopt the following adaptation that addresses this incongruity as follows:
For $d \in \mathbb Z$, let $R_d:\mathbb R \rightarrow \mathbb Z$ such that $$R_d(x) = \begin{cases} \dfrac{\lfloor10^d x + 0.5\rfloor}{10^d}, &x\text{ is nonnegative} \\ \dfrac{\lceil10^d x  0.5\rceil}{10^d}, &x\text{ is negative} \end{cases}$$
Now $R_0(4.5) = R_0(4.5)$! Students rejoice! (Though subsequent teachers unaware of this adaptation will cringe) This even has bias eliminating implications when dealing with aggregate data, however not all bias has been eliminated. The positive bias more or less balances with the negative bias if your mean is at or close to 0, but all the rounding is still biased away from 0. If you are inclined to tackle this you could instead round halves toward the nearest even integer (often referred to as stats rounding or banker's rounding), and we can tweak our definition as follows:
For $d \in \mathbb Z$, let $R_d:\mathbb R \rightarrow \mathbb Z$ such that $$R_d(x) = \begin{cases} \dfrac{\lfloor10^d x + 0.5\rfloor}{10^d}, &x\text{ is nonnegative and }\lfloor10^d x\rfloor\text{ is odd}\\ \dfrac{\lfloor10^d x  0.5\rfloor}{10^d}, &x\text{ is nonnegative and }\lfloor10^dx\rfloor\text{is even}\\ \dfrac{\lceil10^d x  0.5\rceil}{10^d}, &x\text{ is negative and }\lceil10^dx\rceil\text{ is odd}\\ \dfrac{\lceil10^d x + 0.5\rceil}{10^d}, &x\text{ is negative and }\lceil10^dx\rceil\text{ is even} \end{cases}$$
Now you've eliminated the bias away from 0, but you're left with microbiases toward even numbers compared to odd numbers. We could go on an on with different tweaks and variations on rounding, but the bottom line is that you will want to define a method of rounding that is most suitable for the task at hand, and then make sure that you clearly communicate that method of rounding and perhaps even include analysis of its desired advantages and known disadvantages for your particular application.