.ac-power-calc {
max-width: 500px;
margin: 40px auto;
padding: 24px;
border: 2px solid #ccc;
border-radius: 16px;
background-color: #fefefe;
font-family: Arial, sans-serif;
text-align: center;
}

.ac-power-calc h2 {
margin-bottom: 10px;
}

.ac-power-calc p {
margin-bottom: 20px;
font-size: 14px;
color: #555;
}

.ac-power-calc label {
display: block;
margin: 12px 0 6px;
}

.input-row {
margin-bottom: 10px;
}

.input-row input,
.input-row select {
padding: 8px;
margin: 0 5px;
width: 120px;
}

.power-mode-switch {
margin-bottom: 12px;
}

.ac-power-calc button {
padding: 10px 18px;
margin: 12px 6px 0;
border: none;
border-radius: 6px;
cursor: pointer;
font-size: 15px;
}

.calculate-btn {
background-color: #007bff;
color: #fff;
}

.clear-btn {
background-color: #ccc;
color: #000;
}

.result {
margin-top: 16px;
font-weight: bold;
font-size: 17px;
text-align: center;
line-height: 1.8;
}

AC Power Calculator

Calculate real, reactive, and apparent power using AC voltage, current, and power factor.

V
mV
kV

A
mA
kA

Numeric (e.g. 0.8)
Phase Angle (degrees)


function togglePFInput() {
const mode = document.getElementById(‘pfMode’).value;
document.getElementById(‘pfNumericBlock’).style.display = mode === ‘numeric’ ? ‘block’ : ‘none’;
document.getElementById(‘pfAngleBlock’).style.display = mode === ‘angle’ ? ‘block’ : ‘none’;
}

function formatUnit(value, unit) {
if (value >= 1e6) return (value / 1e6).toFixed(3) + ‘ M’ + unit;
if (value >= 1e3) return (value / 1e3).toFixed(3) + ‘ k’ + unit;
return value.toFixed(3) + ‘ ‘ + unit;
}

function calculateACPower() {
const V = parseFloat(document.getElementById(‘acVoltage’).value);
const Vunit = parseFloat(document.getElementById(‘voltageUnit’).value);

const I = parseFloat(document.getElementById(‘acCurrent’).value);
const Iunit = parseFloat(document.getElementById(‘currentUnit’).value);

const pfMode = document.getElementById(‘pfMode’).value;

if (isNaN(V) || isNaN(I)) {
document.getElementById(‘acPowerResult’).innerText = ‘Please enter valid voltage and current.’;
return;
}

let pf, angle;
if (pfMode === ‘numeric’) {
pf = parseFloat(document.getElementById(‘pfValue’).value);
if (isNaN(pf) || pf 1) {
document.getElementById(‘acPowerResult’).innerText = ‘Enter a valid power factor (0 to 1).’;
return;
}
angle = Math.acos(pf);
} else {
angle = parseFloat(document.getElementById(‘pfAngle’).value) * Math.PI / 180;
if (isNaN(angle)) {
document.getElementById(‘acPowerResult’).innerText = ‘Enter a valid angle in degrees.’;
return;
}
pf = Math.cos(angle);
}

const voltage = V * Vunit;
const current = I * Iunit;

const apparentPower = voltage * current; // VA
const realPower = apparentPower * pf; // W
const reactivePower = apparentPower * Math.sin(angle); // VAR

const resultHTML = `
Real Power: ${formatUnit(realPower, ‘W’)}
Reactive Power: ${formatUnit(reactivePower, ‘VAR’)}
Apparent Power: ${formatUnit(apparentPower, ‘VA’)}
`;

document.getElementById(‘acPowerResult’).innerHTML = resultHTML;
}

function clearACPower() {
document.getElementById(‘acVoltage’).value = ”;
document.getElementById(‘acCurrent’).value = ”;
document.getElementById(‘pfValue’).value = ”;
document.getElementById(‘pfAngle’).value = ”;
document.getElementById(‘acPowerResult’).innerText = ”;
}

(adsbygoogle = window.adsbygoogle || []).push({});