Exact formula for the magnetization of the Ising model