In one place, I am determining the percentageDifference
by adding the baseValue
and targetValue
. However, in another location, I am calculating the targetValue
using the baseValue
and percentageDifference
. The problem I encounter is that the result of the first calculation for the percentageDifference
does not match the targetValue
obtained from the second calculation.
How can I ensure that all calculations consistently use the same 3 values?
// Calculate targetValue
let baseValue = 50.8998;
let percentageDifference = 0.01;
let change = (percentageDifference / 100.0) * baseValue;
let targetValue = baseValue + change;
// Calculate percentageDifference
let baseVal = 50.8998;
let targetVal = 55.7878;
let percentDiff = Math.abs(baseVal - targetVal) / baseVal;
let percDiff = percentDiff * 100.0;