DEV Community

Param Mehta
Param Mehta

Posted on

I Built a Free Metal Weight Calculator — Here's the Math Behind It

I'm not a professional developer. I'm a steel fabricator who got tired of calculating pipe weights on paper.
So I built MetalWeightPro — a free, browser-based metal weight calculator for Indian fabricators. No framework. No backend. Just vanilla HTML, CSS, and ES modules.
Here's the math that powers it.


The Core Formula
Every section type has a different cross-sectional area. Weight is always:

W = A × L × ρ
Enter fullscreen mode Exit fullscreen mode

Where:
W = weight in kg
A = cross-sectional area in m²
L = length in metres
ρ = material density in kg/m³

The only thing that changes per section type is how you calculate A.

Round Bar

// D in mm, returns kg/m
function roundBarWeight(D, density = 7850) {
  const area = (Math.PI / 4) * Math.pow(D / 1000, 2);
  return area * density;
}

// Simplified constant form
function roundBarWeightSimple(D) {
  return (D * D) / 162;
}

// Example: 25mm MS round bar
console.log(roundBarWeightSimple(25)); // 3.858 kg/m
Enter fullscreen mode Exit fullscreen mode

Hollow Pipe

// OD and t in mm, returns kg/m
function pipeWeight(OD, t, density = 7850) {
  const outerArea = (Math.PI / 4) * Math.pow(OD / 1000, 2);
  const innerArea = (Math.PI / 4) * Math.pow((OD - 2 * t) / 1000, 2);
  return (outerArea - innerArea) * density;
}

// Simplified form
function pipeWeightSimple(OD, t) {
  return (OD - t) * t * 0.0246615;
}

// Example: 60.3mm OD, 3.65mm wall (2" IS 1239 medium)
console.log(pipeWeightSimple(60.3, 3.65)); // 5.10 kg/m
Enter fullscreen mode Exit fullscreen mode

Hollow Section (SHS/RHS)

// All dimensions in mm, returns kg/m
function hollowSectionWeight(B, H, t, density = 7850) {
  const outerArea = (B / 1000) * (H / 1000);
  const innerArea = ((B - 2 * t) / 1000) * ((H - 2 * t) / 1000);
  return (outerArea - innerArea) * density;
}

// Example: 50×50×3mm SHS (IS 4923)
console.log(hollowSectionWeight(50, 50, 3)); // 4.45 kg/m
Enter fullscreen mode Exit fullscreen mode

plaintext

MS Angle

// A, B = leg lengths in mm, t = thickness in mm
function angleWeight(A, B, t, density = 7850) {
  const area = ((A + B - t) * t) / 1000000;
  return area * density;
}

// Example: 65×65×6mm equal angle (IS 808)
console.log(angleWeight(65, 65, 6)); // 5.84 kg/m
Enter fullscreen mode Exit fullscreen mode

plaintext

Material Densities

const DENSITIES = {
  mild_steel:      7850,
  stainless_steel: 8000,
  aluminium:       2700,
  copper:          8960,
  brass:           8500,
  cast_iron:       7200,
  gi:              7850,
  lead:            11340
};
Enter fullscreen mode Exit fullscreen mode

plaintext

The Divisor Pattern

// Divisor = 1,000,000 ÷ (π/4 × density)
function getDivisor(density) {
  return 1000000 / ((Math.PI / 4) * density);
}

console.log(getDivisor(7850));  // 162.3 → MS
console.log(getDivisor(8000));  // 159.2 → SS
console.log(getDivisor(2700));  // 471.5 → Aluminium
console.log(getDivisor(8960));  // 142.5 → Copper
Enter fullscreen mode Exit fullscreen mode

This is why fabricators say D²/162 for MS but the formula is universal — just swap the divisor for the material.

Stack
Zero framework — vanilla ES modules
Hosted on Google Cloud Storage + Cloudflare
No build step for the calculators — just math in the browser
jsPDF for template downloads in the notching tool
Try It
👉 MetalweightPro
All three tools are free. No login. Mobile friendly. Follows Indian IS standards.
Would love feedback from developers and engineers both — what would you add?

Top comments (0)