You are correct in your use of the following mathematical expression.

formal charge = group # - 1/2(bonded electrons) - non-bonded electrons