You can convert the dimensions to counters, wheras their division results to an truncated integer, but a simple division will give you problematic results. The division is: How often does q (\textwidth) go in p (\heightoftext)?
The mathematical formula would be ceil(p/q) (rounding up). As p and q are integer values (counters in TeX) we can implement the ceiling function with a little trick.
Let’s take a look at q = 4, p = 2, …, 9:
p │ 9 8 7 6 5 4 3 │
─────────────────────┼───────────────────────┼────────────────────────────────────────
int( p / q) │ 2 2 1 1 1 1 0 │ what we get
ceil( p / q) │ 3 2 2 2 2 1 1 │ what we want
int( p / q) + 1 │ 3 3 2 2 2 2 1 │ what works for p/q ≠ int(p/q)
int((p–1) / q) + 1 │ 3 2 2 2 2 1 1 │ = ceil(p/q)
The second last row needs to be shifted by one to get the actual ceiling function what we achieve by subtracting 1 from q.
\def\divideMeCount#1#2{%
\countp=#1\relax%
\advance\countp by -1\relax%
\countq=#2\relax%
\divide\countp by \countq\relax%
}
Another solution uses a loop effectively counting the pages:
\def\divideMeLoop#1#2{%
\dimenp=#1\relax%
\dimenq=#2\relax%
\tempi=0\relax%
\loop\advance\dimenp by -\dimenq\relax\advance\tempi by 1\relax%
\ifdim\dimenp>0pt\relax\repeat%
}
Values
\textheight = 550.0pt
\heightofbox =
Code
\documentclass{article}
\newcount\countp
\newcount\countq
\newdimen\dimenp
\newdimen\dimenq
\newcount\tempi
\newdimen\heightofbox
\def\divideMeCount#1#2{%
\countp=#1\relax%
\advance\countp by -1\relax%
\countq=#2\relax%
\divide\countp by \countq\relax%
}
\def\divideMeLoop#1#2{%
\dimenp=#1\relax%
\dimenq=#2\relax%
\tempi=0\relax%
\loop\advance\dimenp by -\dimenq\relax\advance\tempi by 1\relax%
\ifdim\dimenp>0pt\relax\repeat%
}
\usepackage{pgf}
\begin{document}
\heightofbox=1099pt\relax
\the\heightofbox/\the\textheight\par
{\bfseries Counters\par}
\divideMeCount{\heightofbox}{\textheight}
counpt+1=\number\numexpr\countp+1\relax\par
{\bfseries Dimensions (Loop)\par}
\divideMeLoop{\heightofbox}{\textheight}
tempi=\the\tempi\par
{\bfseries PGF (example)\par}
\pgfmathtruncatemacro{\result}{ceil(\heightofbox/\textheight)}
result=\result
\bigskip
\heightofbox=1100pt\relax
\the\heightofbox/\the\textheight\par
{\bfseries Counters\par}
\divideMeCount{\heightofbox}{\textheight}
counpt+1=\number\numexpr\countp+1\relax\par
{\bfseries Dimensions (Loop)\par}
\divideMeLoop{\heightofbox}{\textheight}
tempi=\the\tempi\par
{\bfseries PGF (example)\par}
\pgfmathtruncatemacro{\result}{ceil(\heightofbox/\textheight)}
result=\result
\bigskip
\heightofbox=1101pt\relax
\the\heightofbox/\the\textheight\par
{\bfseries Counters\par}
\divideMeCount{\heightofbox}{\textheight}
counpt+1=\number\numexpr\countp+1\relax\par
{\bfseries Dimensions (Loop)\par}
\divideMeLoop{\heightofbox}{\textheight}
tempi=\the\tempi\par
{\bfseries PGF (example)\par}
\pgfmathtruncatemacro{\result}{ceil(\heightofbox/\textheight)}
result=\result
\end{document}
Output
