ROA_Calc/roacalc.js

35 lines
1.3 KiB
JavaScript
Raw Normal View History

2024-07-03 00:26:16 -04:00
function getROA() {
// Get values from page
var startSize = document.getElementById("startSize").value;
var finalSize = document.getElementById("finalSize").value;
// If mm is selected we convert it to inches
if (document.getElementById("metric").checked == true) {
startSize = Math.round((startSize * 1000) / 25.4);
}
// Format our numbers to prevent maximum user stupidity
if (startSize < 1.0 && startSize > 0) { // If we have a 'proper' number i.e. ".130"
startSize = startSize * 1000;
} else { // re-format the number if it's 'wrong' i.e. "130"
startSize = Number(startSize);
}
if (finalSize < 1.0 && finalSize > 0) { // If we have a 'proper' number i.e. ".130"
finalSize = finalSize * 1000;
} else { // re-format the number if it's 'wrong' i.e. "130"
finalSize = Number(finalSize);
}
// Get area from diameter
var startArea = Math.PI * ((startSize / 2) * (startSize / 2));
var finalArea = Math.PI * ((finalSize / 2) * (finalSize / 2));
// Calculate reduction
var reduction = ((startArea - finalArea) / startArea) * 100;
// Round to two decimals
reduction = Math.round(reduction * 100) / 100;
// Display
document.getElementById("result").innerHTML = reduction + "%";
}