One way to think about it -- When you have a statement like "There are 1000 milligrams in one gram", the 1000 will always go with the mg. If you want the mg on the bottom, you have 1 g/1000mg. If you want the mg on the top, you have 1000mg/1g. There's no other way to write it which makes it equal to 1.
A good way to check -- in the question you gave, you know that grams are bigger than milligrams, so if you have 3 grams, when you convert to milligrams, the number of milligrams should get bigger. If you divide by 1000 accidentally, you get a number much smaller than 3, which tells you that you made an error.