I have a function which will produce array value from currentTime of timer by clicking button. In this case this is the result:
var data_catch = ["0", "24.871604", "27.1788", "29.69", "29.100", "30.570661"];
And then I need to get duration between array value with rules "the next value will reduce by previous value" which leads me to use this way:
var data_duration = [];
for (var i = 1; i < data_catch.length; i++) {
data_duration.push(data_catch[i]-data_catch[i-1]);
}
console.log(data_duration);
The value of data_duration
should never be minus, because the timer always going ahead and the currentTime always have bigger value than previous currentTime. But in this case the result of data_duration is :
data_duration = [
24.871604,
2.3071959999999976,
2.5112000000000023,
-0.5899999999999999,
1.4706609999999998
];
The result have one minus value because of this reduction 29.100 - 29.69
Why this is happen and how to fix this? Please help me..