Many measurement conversions are very simple, but converting milliliters to grams is a little more complicated because you are trying to convert a volume unit to a mass unit. In fact, there is no single formula to convert between them. You need to find the formula based on the object you are measuring.
TL;DR (Too Long; Didn't Read)
To convert milliliters to grams, you need to convert one type of unit (volume) to another (mass). To do this, you first need to know the density of your object. You then multiple its volume in milliliters by its density to find out its mass in grams.
Volume and Mass
Before converting milliliters to grams, it's important to understand the difference between volume and mass. Milliliters is a volume unit and grams is a mass unit. Volume is the amount of space something takes up. One milliliter of water and one milliliter of air take up the same amount of space. On the other hand, mass is the amount of matter. You can make an object smaller to change its volume, but this will not change its mass. Grams are often used to measure weight, which isn't quite the same as mass. Weight measures the force of gravity on mass.
Density (mass per unit volume) helps you work out much mass in grams fits into one milliliter volume and can therefore be used to convert between the two measurements. If you are answering a math or chemistry problem, you may be given the object's density. If not, you can refer to a chart. Charts are available for everything from pure elements to food and drink. For example, the density of zinc is 7.14 g/cm3 and the density of copper is 8.96 g/cm3 while the density of water is 1 g/cm3, the density of skimmed milk is 1.033 g/cm3 and the density of butter is 0.911 g/cm3.
Convert Volume to Mass
When you know the density of your object, you can use this to convert volume to mass. To convert for copper, multiply the volume by 8.69. For example, 8 milliliters of copper has a mass of 69.52 grams. To convert for skimmed milk, multiply your volume by 1.033. For example, 40 milliliters of skimmed milk has a mass of 41.32 grams. The most simple conversion is for water; in fact, you don't need to do anything. One milliliter of water has one gram of mass.