How to evaluate an integral with the floor function?
One can use the Fourier series representation of the floor function: $\lfloor x\rfloor=\frac{1}{\pi}\sum _{k=1}^{\infty } \frac{1}{k}\sin (2 \pi k x)+x-\frac{1}{2}$. Integrating the $(x-1/2)$ we obtain your expected answer.
Integrate[(n x - 1/2), {x, 0, 1}]
$\frac{n}{2}-\frac{1}{2}$
For the rest, we can verify that it gives zero contribution.
res = 1/π Sum[Integrate[Sin[2 π k x n], {x, 0, 1}]/k, {k, 1,Infinity}]
$\frac{-3 \text{Li}_2\left(e^{-2 i n \pi }\right)-3 \text{Li}_2\left(e^{2 i n \pi }\right)+\pi ^2}{12 \pi ^2 n}$
FullSimplify[res, Assumptions -> n ∈ Integers]
(*0*)
FindSequenceFunction[
Table[
Integrate[Floor[n*x], {x, 0, 1}],
{n, 10}],
n] ==
Sum[k/n, {k, 0, n - 1}] ==
(n - 1)/2
(* True *)
If you specify a range for n, then you can use PiecewiseExand and integrate:
Integrate[PiecewiseExpand[Floor[n x], {0 < x < 1, 0 < n < 5}], {x, 0, 1}]