# $\operatorname{card}\bigl((a,b]\cap \Bbb{Z}\bigr)=\lfloor b\rfloor-\lfloor a\rfloor$ for $a,b\in \Bbb{R}$

I was playing with my little brother with numbers when some examples suggested that for any $a,b\in \Bbb{R}$ we have $$\operatorname{card}\bigl((a,b]\cap \Bbb{Z}\bigr)=\lfloor b\rfloor-\lfloor a\rfloor.$$

Unfortunately I don't see how can I prove that, when we count the left side we see that is always the right side but it's not a proof.

• It might help to work out the case when there are no integers in $(a,b]$. After that you can proceed to "expand" the proof by breaking the interval $(a,b]$ into smaller pieces. – hardmath Sep 17 '17 at 22:45

Hint: solve for $\,a=0\,$ to get the intutition. Then use that $\operatorname{card}\bigl((a,b]\cap \Bbb{Z}\bigr)=\operatorname{card}\bigl((\lfloor a \rfloor,b]\cap \Bbb{Z}\bigr)\,$, since the (possibly empty) interval $(\lfloor a \rfloor,a)$ never contains an integer.
Assuming $a<b$, the largest integer less than or equal to $b$ is $\lfloor b\rfloor$ and the largest integer less than or equal to $a$ is $\lfloor a\rfloor$. So an integer $n$ belongs to $(a,b]$ if and only if $$\lfloor a\rfloor+1\le n\le\lfloor b\rfloor$$ Now, just count.