Calculation of total charge