Years ago, when I was doing laboratory programming, I wrote a set of c++ classes for numbers with units. It tracked units through the calculations (and managed significant figures). It even allowed for such stuff as dividing mass by volume to return a density or generating a volume by multiplying three lengths together. It was very useful for the task at hand, which was flowmeter calibration.