Measuring grams of liquid in a gallon requires knowledge about the type of liquid and its weight for conversion. In order to calculate grams in a gallon of liquid, its density must be known. Information regarding a liquid's density allows conversion between mass and volume, such as gallons to grams.
Grams and gallons are different types of units of measurement. Grams are used as units that represent weight, while gallons are used as units that represent volume. Density is defined as mass per volume. Mass and weight are almost synonymous, as weight is simply the amount of force exerted by a mass due to gravity.