31 lines
966 B
JavaScript
31 lines
966 B
JavaScript
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 error
|
|
if (startSize > 100) {
|
|
startSize = startSize / 1000;
|
|
}
|
|
if (finalSize > 100) {
|
|
finalSize = finalSize / 1000;
|
|
}
|
|
|
|
// 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 + "%";
|
|
} |