As we know that fundamental charge due to an electron is given by

so here we will say that charge on an atom due to loss of electron is termed as positive charge while due to gain of electron it is negative charge
Here when magnesium loses two electrons it will become positively charged
And total charge on it is given as

now we know that
N = 2 electrons
so charge on it is given as

