Calculation of statistical properties of nuclei in a finite-temperature mean-field theory requires projection onto good particle number, since the theory is formulated in the grand canonical ensemble. This projection is usually carried out in a saddle-point approximation. Here we derive formulas for an exact particle-number projection of the finite-temperature mean-field solution. We consider both deformed nuclei, in which the pairing condensate is weak and the Hartree-Fock (HF) approximation is the appropriate mean-field theory, and nuclei with strong pairing condensates, in which the appropriate theory is the Hartree-Fock-Bogoliubov (HFB) approximation, a method that explicitly violates particle-number conservation. For the HFB approximation, we present a general projection formula for a condensate that is time-reversal invariant and a simpler formula for the BardeenCooper-Schrieffer (BCS) limit, which is realized in nuclei with spherical condensates. We apply the method to three heavy nuclei: a typical deformed nucleus 162 Dy, a typical spherical nucleus 148 Sm, and a transitional nucleus 150 Sm in which the pairing condensate is deformed. We compare the results of this projection with results from the saddle-point approximation and exact shell model Monte Carlo calculations. We find that the approximate canonical HF entropy in the particlenumber projection decreases monotonically to zero in the limit when the temperature goes to zero. However, in a nucleus with a strong pairing condensate, the approximate canonical HFB entropy in the particle-number projection decreases monotonically to a negative value, reflecting the violation of particle-number conservation. Computationally, the exact particle-number projection is more efficient than calculating the derivatives required in the saddle-point approximation.