DEV Community

Agoes Jayanata
Agoes Jayanata

Posted on

Calculating Pool Volume for Rectangles, Circles and Ovals in JavaScript

If you've ever shocked a pool, balanced its chemistry, or ordered a fresh bag of salt for a salt-chlorine system, you already know the rule: the dose depends on the volume, and the volume depends on the shape. Swimming pools come in rectangles, circles, and ovals, and each one has its own volume formula. The good news is that they all collapse into a single area × average depth pattern, and a few lines of JavaScript are enough to cover every case a DIY calculator will meet.

The first detail that trips people up is depth. Most pools slope from a shallow end to a deep end, so a single depth number doesn't describe the water. The standard fix is to average the two:

averageDepth = (shallowDepth + deepDepth) / 2

Use that average everywhere in the rest of the math. For a rectangular pool, the volume in cubic feet is straightforward:

volumeFt3 = lengthFt * widthFt * averageDepthFt
Pool chemicals and fill rates are in gallons, not cubic feet. One cubic foot of water equals 7.48 gallons, so:

gallons = volumeFt3 * 7.48

A circle is a rectangle with a different area. The surface area is π × radius², and the radius is half the diameter:

volumeFt3 = Math.PI * radiusFt * radiusFt * averageDepthFt

An oval (or ellipse) is the tricky one. The exact area of an ellipse is π × semiMajor × semiMinor, which in pool math is almost always rewritten with the 0.785 approximation factor:

area ≈ 0.785 * lengthFt * widthFt

The 0.785 is π/4, and it converts a length × width rectangle into the ellipse's area. Multiply by average depth and you have the volume:

volumeFt3 = 0.785 * lengthFt * widthFt * averageDepthFt
That lets you write one JavaScript function that covers every shape:

function poolVolumeGallons(shape, dimensions, shallowDepthFt, deepDepthFt) {
  const avgDepth = (shallowDepthFt + deepDepthFt) / 2;
  let volumeFt3;
  if (shape === 'rectangle') {
    volumeFt3 = dimensions.length * dimensions.width * avgDepth;
  } else if (shape === 'circle') {
    const r = dimensions.diameter / 2;
    volumeFt3 = Math.PI * r * r * avgDepth;
  } else if (shape === 'oval') {
    volumeFt3 = 0.785 * dimensions.length * dimensions.width * avgDepth;
  }
  return volumeFt3 * 7.48;
}
Enter fullscreen mode Exit fullscreen mode

A 16 ft × 32 ft oval, 3 ft shallow and 9 ft deep:

poolVolumeGallons('oval', { length: 32, width: 16 }, 3, 9)
≈ 0.785 × 32 × 16 × 6 × 7.48 ≈ 18,160 gallons

The pool volume calculator walks through this exact pattern for each shape, including the average-depth step.

Salt Dosing From the Volume

Once you trust your gallon count, chemistry becomes straightforward. The most common calculation is salt dosing for a salt-chlorine generator. The formula the industry uses is:

pounds of salt = gallons × ppmDifference × 8.34 / 1,000,000

The 8.34 is the weight of a gallon of water in pounds (water weighs about 8.34 lb/gal), and the 1,000,000 converts the parts-per-million ratio into actual pounds. In JavaScript:

function saltPoundsNeeded(gallons, currentPPM, targetPPM) {
  const ppmDiff = targetPPM - currentPPM;
  if (ppmDiff <= 0) return 0;
  return (gallons * ppmDiff * 8.34) / 1e6;
}

saltPoundsNeeded(18160, 1500, 3500) ≈ 308 pounds
Enter fullscreen mode Exit fullscreen mode

For the 18,160-gallon oval above, raising salinity from 1,500 ppm to 3,500 ppm calls for about 308 pounds of salt. Note the guard clause: if the current reading is already at or above the target, the function returns zero instead of a meaningless negative number.

A 10,000-gallon rectangular pool that's at 2,500 ppm and needs 3,500 ppm only needs roughly 83 pounds. Same formula, different volume — which is exactly why getting the volume right matters more than memorizing the salt constant.

Wrapping Up

Pool volume is one of those calculations where the math is honest and the mistakes are human: measure the shallow and deep ends separately, average them, pick the right shape factor (1.0 for rectangles, π for circles, 0.785 for ovals), multiply through, and convert at the end with 7.48. Get the gallons right and every downstream dose — shock, algaecide, pH adjuster, salt — scales from the same number.

If you're putting a pool calculator together, the single poolVolumeGallons function above is a clean start. Add the salt dosing helper next, and you already cover the two questions pool owners ask most often. The pool volume calculator and salt pool calculator show the worked-out versions, including the average-depth step and the ppm-guard clause.

Top comments (0)