In more detail
Multiply each value by its weight, add the products and divide by the sum of the weights. When the weights are percentages that add up to 100%, the division is by 1 and can be skipped; when they do not (credit hours, quantities, minutes), it cannot. Marks of 90, 80 and 70 weighted 40%, 30% and 30% give 81, where the plain mean would be 80. Course grades work the same way, with credit hours as the weights, as in a GPA.
Why it matters
Whenever values stand for groups of different size, the plain average is wrong. Averaging average prices, average speeds or percentages from groups of unequal size are the classic traps. A weighted average always lies between the smallest and largest values, which makes a quick sanity check.
Example
100 shares at 10, then 50 shares at 20
average cost = (100 × 10 + 50 × 20) / 150 = 13.33 (not 15)
60 km/h out, 40 km/h back over the same 60 km
time = 1 h + 1.5 h = 2.5 h
average speed = 120 km / 2.5 h = 48 km/h (not 50)
The speeds must be weighted by the time spent at each, not by the distance; more time is spent at the slower speed.
Common confusion
The plain mean is a weighted average in which every weight is 1. Use the weighted form whenever the values do not all carry the same importance.