A product 34 yuan bought 10, and B product 45 yuan bought 20. What is the average price of product A and product B? At this time, the arithmetic average can't be directly used as (34+45)/2, because they buy different quantities, so to calculate their average price, they can only use the quantity they buy as the weight and carry out weighted average: (34×10+45× 20)/(10+20) = 65430.
An algorithm like this.