Milligrams and gallons measure two different things and cannot be equated. However, if the substance in question is water, then 1 gallon of water is equal to 3785.411784 milligrams of water in most cases.
A milligram is a unit used to measure mass, and a gallon is used to measure volume. For water, 1 milligram takes up exactly 1 cubic centimeter. According to UnitConversion.org, 1 gallon is equal to 3785.411784 cubic centimeters. Not all substances have this convenient conversion, however. Other substances have different densities. Density is a ratio of units mass per unit volume. Density can be affected by air pressure, so depending on the altitude at which the measurement is taken, the previously stated conversion of water may not be accurate.