In general, I wouldn't trust a formula (especially one with magic numbers in it) that doesn't have the units specified...
But in any case, you can derive it by starting with the reaction associated with black powder 2(KNO3) + 3(C) + S => K2S + N2 + 3(CO2) and PV=nRT.
For now lets assume that we have an airframe that is 10cm in diameter, and 100cm long. The volume of that is V=pi*(d/2)^2*h, or 7700 cm^2, or 7.8L.
Now we want to increase the pressure of our airframe to be 15PSI, or one atmosphere, more than what was in there. So that means that we need to add enough BP to fill a 7.8L volume to 1atm.
The only variable left now is T, which needs to be the temperature of the gas produced by the BP... This is a tricky one, as the gas expands it will cool, but it is generally considered safe to assume it is 1500K
We rearrange PV=nRT to solve for n, giving us n=PV/RT, and use R = .082 L atm/K mol for the ideal gas constant, which gives us .056moles of gas necessary.
Then we can examine the equation for the combustion of black powder, and note that there are 5 moles of gas on the product side of the reaction. For simplicity's sake, we will only consider the N2 produced, as we can determine from the coefficients in the equation that N2 will consist of exactly 1/5th of the total gas produced. We cam then use ratios to solve for the amount of N2 needed, (1mol N2 / 5 mol total) = (X mol N2 / .056 mol total), which solves to .011mol N2.
We can then use this value to solve for the amounts of KNO3, C and S by using their molar masses, and their coefficient in the reaction. For S we simply multiply the molar mass of S (32g/mol) times the coefficient of S in the reaction (1) and then the number of moles of N2 disired (.011mol), which gives .36g. The same is true for C and KNO3, which gives .40g and 2.2g respectively. These are then added, to give a total of 3g necessary.
But since no one wants to sit down and go through that every time they need to fill their rocket with BP, we can wite an equation that relates whatever variables you want (airframe diameter, length, pressure, weight of BP) being careful to keep the powers correct.
ie, Wbp = L * D^2 * P * x
Plugging in the values used (3g, 100cm, 10cm, 15psi respectively) and solving for x would give .00002.
If we wanted to use inches instead, we could convert the measurements to inches at this point, and solve again (3g = 40in * 16in * 15psi *x ), which gives us x=0.0003, quite close to the value presented in the first post
Of course there are better ways to solve this, but sometime the long way helps people understand what is going on...