When you are writing software for logistics or trading companies, sooner or later you might have to deal with the concept of dimensional weight (sometimes called ‘volumetric weight’).
What Is Dimensional (Volumetric) Weight?
The first time I faced the term of dimensional weight, I was quite confused. So let me explain the background a little bit.
Simply spoken, dimensional weight is an additional number used when you ship a box via one of the big carriers like UPS, FedEx or DHL. The basic formula is
dimensional weight (kg) = box volume (cm³) / 5000
(There are variants of this formula, but that’s not important for the moment. The logic behind is always the same.)
Remembering your physics course back in high school, you see that units are not the same on the left and the right side of this equation. Weight is measured in kg, volume is measure in cm³, so isn’t this just a mistake? Well, what you have to accept is that ‘dimensional weight’ has no physical meaning. Rather it is a number used by logistics companies to simplify their cost calculations.
When  let’s say  UPS ship a box from A to B, they probably use a truck for transportation. The truck has a maximum loading weight, which is maybe 1000 kg. So the heavier your box is, the more capacity of the truck is used for your box. As a simplification, we might assume that cost is proportional to the weight. (For 1 kg you may pay 5$, for 2kg 10$.)
But there’s another limiting factor in the truck: the volume. You can only put up to maybe 10 m³ of stuff into the truck. So the second thing UPS needs to consider is how volumetric your box gets. If your box is very light but also very big, this somehow needs to go into the cost calculation. Dimensional weight is a concept to make this calculation easier. You can put it like this:
For a light and big box, dimensional weight is the weight of that tiny and heavy box which creates the same cost of transportation.
Implementation Details
At least UPS claims that dimensional weight is always rounded up to the next whole kilogram. So even for 1.01 kg, they may charge you 2 kg.
Sample Code
Note: You should check proper rounding method for your carrier and your country. The implementations below are for UPS.
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 

Excel
1 2 3 4 5 6 
