I think the easiest way to understand what is going on here is to imagine summing up the gravitational field at a point due to a bunch of point charges. Let's take your "center of gravity" example. If we have two point charges in one dimension, the center of gravity is given by:
$$x_{cm} = \frac{m_{1}x_{1} + m_{2}x_{2}}{m_{1} + m_{2}}$$.
, and it should be clear that as we add more and more masses, we get something like:
$$x_{cm} =\frac{\sum_{i}m_{i}x_{i}}{\sum_{i}m_{i}}$$
Often in physics, though, we want to worry about these things for the case of continuous distributions of matter, in which case, we can think of the distibution as an infinite number of infinitesimal masses, which, in the language of calclulus, means converting the sum into an integral, which means:
$$x_{cm} = \frac{\int dm\,x}{M}$$
where $M$ is the total mass. In practice, we rarely work with x as a function of m, though, and instead, we have density functions, and write something like:
$$M = \int dx \rho$$
, which implies $dm = \rho dx$, and consequently, think of the center of mass equation as:
$$x_{cm} = \frac{\int dx \rho(x) x }{M}$$
In fact, if you know the dirac delta function, you can write the first "sum" equation this way, with the density function:
$$\rho(x) = m_{1}\delta(x - x_{1}) + m_{2}\delta(x-x_{2})$$
whose integral will simply evaluate out to the first equation.