Functional Weave
Code in TypeScript

retail.volumetric-weight@1.0.0

README.md

1,299 bytes · view raw

# retail.volumetric-weight

Carriers charge for the space a parcel takes as well as its weight. The
volumetric weight is `length x width x height / divisor`, where the divisor is
in cubic centimetres per kilogram (5000 for most express couriers, 4000 or
6000 for some services), and the chargeable weight is whichever of actual and
volumetric is greater.

Working in millimetres and grams keeps it all integers: mm³ / (cm³/kg) is
exactly grams, because 1 cm³ = 1000 mm³ and 1 kg = 1000 g cancel. A
400 x 300 x 200 mm box at divisor 5000 is 24,000,000 / 5000 = 4800 g.

## Rounding

Two roundings, both up, both documented because both move money:

1. The volumetric weight is rounded up to the whole gram (7385.2 g is 7386 g).
   Carriers never round a parcel's size down.
2. The chargeable weight is rounded up to `roundUpToGrams`, the carrier's
   billing step (most bill in 500 g or 1 kg steps). Pass 1 to leave it at the
   gram.

When the two weights are equal the basis is `actual`.

## Inputs

Measure the longest, widest and tallest points of the packed parcel, bulges
included; that is what the carrier's scanner will do. The order of the three
dimensions does not matter. Carriers that measure in centimetres and round
each dimension first need that rounding done before calling this.