Connell Media

A reference calculation for whole-carton quantities

Inspect the formula, input requirements and test cases behind the whole-carton study.

Inputs and result

The calculation accepts area, allowance percentage and coverage per carton as decimal strings. Area and coverage must be positive. Allowance cannot be negative. The result is an integer carton count; pricing is a separate calculation.

from decimal import Decimal, ROUND_CEILING

def cartons(area, allowance, coverage):
    a, x, c = map(Decimal, (area, allowance, coverage))
    if not all(v.is_finite() for v in (a, x, c)):
        raise ValueError("Use finite numbers")
    if a <= 0 or c <= 0 or x < 0:
        raise ValueError("Check area, coverage and allowance")
    needed = a * (1 + x / 100)
    return int((needed / c).to_integral_value(
        rounding=ROUND_CEILING))

Three useful boundary checks

  • 120 ft², 10% allowance, 22 ft² per carton: six cartons, an exact boundary.
  • 120 ft², 10% allowance, 20 ft² per carton: seven cartons, a fractional boundary rounded up.
  • 120 ft², zero allowance, 20 ft² per carton: six cartons; zero is an explicit input.

Run products independently and add costs afterward. Adding unlike product areas first can produce an invalid shopping list.

Download all reference examples or read the study. This small example demonstrates the arithmetic; it is not a replacement for the full product interface and its input handling.