I was given a formula where below:
weightdifference = (|crushedWeight - weightBA| / weightBA )* 100%
where weightBA and crushedWeight are values of input texts. I did make a function which stated below:
function calDiffWeight() {
var weightDS = document.getElementById("weightDS");
var crushedWeight = document.getElementById("crushedWeight");
var abs = -1;
var diffWeight = ((crushedWeight - weightDS) * abs) / weightDS * 100;
document.getElementById("diffWeight").value = diffWeight;
}
and for the absolute calculation in |crushedWeight - weightBA|
how should i do it?