The density given is 1.04 g/mL, or also equivalent to:
density = 1040 kg/m^3
The total mass of seawater is calculated by multiplying density and volume. conversion factor is 1 km = 1000 m:
total mass = (1040 kg/m^3) * (8.01 km^3) * (1000 m / 1 km)^3
total mass = 8.3304 x 10^12 kg
Since Mg2+ is 0.12% by weight, in fraction this is 0.0012 by weight. So:
mass Mg2+ = (8.3304 x 10^12 kg) * 0.0012
mass Mg2+ = 9.996 x 10^9 kg