Having trouble weighing the sun

$$M_\mathrm{gal}=Rv^2/G$$

($G=6.67\times10^{-11}\ \mathrm{N\cdot(m/kg)^2}$. Units of $v$ and $R$ are km/s and km, respectively)

You gave $G$ in MKS, then: $R$ and $v$ are m, m/s, $1\ \mathrm m= \frac {1}{10^3}\ \mathrm{km}$, that's why you got a wrong result: $10^3 \times (10^3)^2 = 10^9$ that's the order of magnitude you are missing $$ 1.5\times10^{11} \times(3\times10^4)^2/(6.6\times10^{-11}) = 2\times10^{30}\ \mathrm{kg}$$


I think you are doing your math incorrectly if you get $10^{21}\ \mathrm{kg}$.

$$M = \frac{Rv^2}{G}$$ Let's try Jupiter from your reference. $$M = \frac{(778 \times 10^6\ \mathrm{km}) (13.1\ \mathrm{\frac{km}{s}})^2}{G}$$ $$M = \frac{(7.78 \times 10^{11}\ \mathrm m) (1.31 \times 10^4\ \mathrm{\frac{m}{s}})^2}{6.6743 \times 10^{-11}\ \mathrm{\frac{m^3}{kgs^2}}}$$ $$M = \frac{1.34 \times 10^{20}\ \mathrm{\frac{m^3}{s^2}}}{6.6743 \times 10^{-11}\ \mathrm{\frac{m^3}{kgs^2}}}$$ $$M = 2.00\times 10^{30}\ \mathrm{kg}$$