In the metric system anything with the prefix milli will form part of a larger unit. To convert milligrams into grams simply multiply by 1000. This is also true for millilitres and millimetres.

There are 1000 milligrams in one gram, so you would need to divide your number of milligrams by 1000. Conversely to go from grams to milligrams, you multiply by 1000

One gram is equal to 1000 milligrams. Therefore, five hundred milligrams would be a half gram. Simply divide the number of milligrams you have by 1000 and you'll get a decimal, which is that amount in grams.