Example 5 Let $n$ be a positive integer. How many solutions does $x^{2}-\left[x^{2}\right]=$ $(x-[x])^{2}$ have in $1 \leqslant x \leqslant n$?
$(1982$, Swedish Mathematical Olympiad)
Solution: Let $x=n$ be a solution of the equation.
Suppose $1 \leqslant x<n$, then $m=[x], x=m+r$.
Substituting into the given equation, we get
$$
\begin{array}{l}
m^{2}+2 m r+r^{2}-\left[m^{2}+2 m r+r^{2}\right]=r^{2}, \\
2 m r=\left[2 m r+r^{2}\right] .
\end{array}
$$

Thus, $2 m r$ is an integer. Considering $0 \leqslant r<1$, then
$$
r=0, \frac{1}{2 m}, \frac{2}{2 m}, \cdots, \frac{2 m-1}{2 m} \text {. }
$$

For each fixed $m, r$ can take $2 m$ values, i.e., there are $2 m$ solutions.
And $m$ can take $1,2, \cdots, n-1$, then
$$
2(1+2+\cdots+(n-1)):=n(n-1) \text {. }
$$

Including the solution $x=n$, there are a total of
$$
n(n-1)+1=n^{2}-n+1
$$

solutions.