We develop an optimal quantization approach for numerically solving nonlinear filtering problems associated with discrete-time or continuous-time state processes and discrete-time observations. Two quantization methods are discussed: a marginal quantization and a Markovian quantization of the signal process. The approximate filters are explicitly solved by a finite-dimensional forward procedure. A posteriori error bounds are stated, and we show that the approximate error terms are minimal at some specific grids that may be computed off-line by a stochastic gradient method based on Monte Carlo simulations. Some numerical experiments are carried out: the convergence of the approximate filter as the accuracy of the quantization increases and its stability when the latent process is mixing are emphasized.