Range Converter Calculator

Convert a value from one range to another using proportional scaling.

Range 1

Range 2



Result:

function convertRange() {
const r1Low = parseFloat(document.getElementById(“range1Low”).value);
const r1High = parseFloat(document.getElementById(“range1High”).value);
const r1Val = parseFloat(document.getElementById(“range1Value”).value);
const r2Low = parseFloat(document.getElementById(“range2Low”).value);
const r2High = parseFloat(document.getElementById(“range2High”).value);

let output = “”;

if (
isNaN(r1Low) || isNaN(r1High) || isNaN(r1Val) ||
isNaN(r2Low) || isNaN(r2High)
) {
output = “Please fill in all fields to get a result.”;
} else if (r1High === r1Low) {
output = “Range 1 low and high limits cannot be the same.”;
} else {
const scale = (r1Val – r1Low) / (r1High – r1Low);
const result = r2Low + scale * (r2High – r2Low);
output = `Converted Value in Range 2: ${result.toFixed(4)}`;
}

document.getElementById(“rangeResult”).innerHTML = output;
}

function resetRangeCalc() {
document.getElementById(“range1Low”).value = “”;
document.getElementById(“range1High”).value = “”;
document.getElementById(“range1Value”).value = “”;
document.getElementById(“range2Low”).value = “”;
document.getElementById(“range2High”).value = “”;
document.getElementById(“rangeResult”).innerHTML = “”;
}


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