20
$\begingroup$

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.

$\endgroup$
  • 5
    $\begingroup$ There 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. $\endgroup$ – Paul Sinclair Sep 12 at 16:58
  • 7
    $\begingroup$ I'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 $\endgroup$ – Ivo Beckers Sep 13 at 7:34
  • $\begingroup$ @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. $\endgroup$ – richard1941 Sep 18 at 2:36
  • $\begingroup$ @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.. $\endgroup$ – Paul Sinclair Sep 18 at 3:30
  • $\begingroup$ @Paul Sinclair. I apologize. Certainly a very, very common practice in the real world must be right. $\endgroup$ – richard1941 Sep 19 at 5:47
36
$\begingroup$

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, pre-TeX era.

You could also do something like $\mathrm{nint}(x)$, but in formulas that could be cumbersome.

See also the remarks at Mathworld.

$\endgroup$
  • 25
    $\begingroup$ Trouble with $[x]$ is that with any somewhat-complicated expression in the middle it runs the risk of being confused with ordinary square brackets. $\endgroup$ – The_Sympathizer Sep 13 at 0:47
  • $\begingroup$ Exactly, I now prefer the other one now $\endgroup$ – Rayreware Sep 13 at 10:02
  • 1
    $\begingroup$ $\lfloor x \rceil$ is highly used in modern Cryptography. $\endgroup$ – kelalaka Sep 14 at 18:49
  • $\begingroup$ Isn'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. $\endgroup$ – chepner Sep 14 at 22:16
23
$\begingroup$

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 half-integer 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.

$\endgroup$
  • 9
    $\begingroup$ Please, please don't use simple square brackets for rounding. They are already used for far too many other things. $\endgroup$ – leftaroundabout Sep 13 at 9:43
  • 3
    $\begingroup$ @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 readily-available 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. $\endgroup$ – Arthur Sep 13 at 10:11
  • 5
    $\begingroup$ Please never use the "round-up 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. $\endgroup$ – Carl Witthoft Sep 13 at 11:27
  • 1
    $\begingroup$ @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]$. $\endgroup$ – leftaroundabout Sep 13 at 11:53
22
$\begingroup$

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 half-integers. (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.)

$\endgroup$
9
$\begingroup$

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 “ninn-t?”

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”.

$\endgroup$
  • 1
    $\begingroup$ I prefer this notation, but the ambiguity of "round" 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. $\endgroup$ – Eric Towers Sep 13 at 13:58
2
$\begingroup$

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$).

$\endgroup$
1
$\begingroup$

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.

$\endgroup$
0
$\begingroup$

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 $$

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.