If you've ever built a deck, framed a shed, or ordered concrete for a patio, you've probably reached for a calculator at some point. DIY calculators are useful, but the unit conversions behind them follow the same small patterns every time. Two of the most common are board feet, which measure lumber, and cubic yards, which measure bulk materials like dirt, mulch, and concrete.
Both reduce to a tiny formula and a few lines of JavaScript. Below I'll show one function for each, the gotchas that make the difference between a clean build and a truckload of waste, and links to ready-made calculators you can try.
Board Feet
A board foot is the standard unit for pricing lumber in the U.S. It represents a piece of wood 1 inch thick, 12 inches wide, and 12 inches long — exactly one cubic foot of volume expressed in lumber terms. The formula is simple:
board feet = thickness(in) × width(in) × length(ft) / 12
In JavaScript it becomes a single function:
function boardFeet(thicknessIn, widthIn, lengthFt) {
return (thicknessIn * widthIn * lengthFt) / 12;
}
Call it with the actual measured dimensions, not the label on the sticker. A "2×4×8" stud is sold by its nominal size, but a dressed 2×4 is closer to 1.5 inches by 3.5 inches thick. Using the nominal 2 and 4 would overstate your board feet and make your takeoff look cheaper than it really is.
For example, a true 2×4 that is 1.5 in thick, 3.5 in wide, and 8 ft long:
boardFeet(1.5, 3.5, 8) → (1.5 × 3.5 × 8) / 12 = 3.5 board feet
If you used the nominal 2 and 4 instead, you'd get 5.33 board feet — over 50% more. That's why every serious lumber takeoff uses actual dimensions.
A worked-out version lives in this board foot calculator, which walks through the thickness, width, and length step by step.
Cubic Yards
Cubic yards is how ready-mix concrete, topsoil, and mulch are sold. The formula starts in feet and divides by 27, because one cubic yard equals 27 cubic feet (3 ft × 3 ft × 3 ft):
cubic yards = length(ft) × width(ft) × depth(ft) / 27
The JavaScript version is equally short:
function cubicYards(lengthFt, widthFt, depthFt) {
return (lengthFt * widthFt * depthFt) / 27;
}
A 12 ft × 8 ft patio poured 4 inches deep (0.333 ft):
cubicYards(12, 8, 0.333) ≈ 1.18 cubic yards
Here's where beginners trip up. You don't order 1.18 yards of concrete — suppliers deliver by the yard and you want a little extra for spill, windrows, and form variation. The standard practice is to round up to the nearest tenth or a quarter-yard and add 5-10% for waste:
function yardsToOrder(lengthFt, widthFt, depthFt, wastePct = 0.1) {
const exact = cubicYards(lengthFt, widthFt, depthFt);
return Math.ceil((exact * (1 + wastePct)) * 10) / 10;
}
yardsToOrder(12, 8, 0.333) → 1.3 cubic yards
The / 27 is the entire math; everything else is the real world. A complete walk-through is in this cubic yard calculator, including inch-to-feet depth conversion.
Why These Two Together
Board feet and cubic yards show up on almost the same job. You'll calculate board feet for the framing, then cubic yards for the footing concrete that holds it. Both formulas are one multiplication chain and one division; the judgment calls — actual vs nominal dimensions, and rounding up for purchase — are what separate a useful calculator from a dangerous one.
If you're building a DIY estimator, start with these two functions. Keep thickness, width, and length in their native units so the function signature tells you the unit at the call site, and round up on anything the customer pays for. You can try the board foot calculator and cubic yard calculator side by side to see how the same pattern repeats across different materials.
Top comments (0)