I am attempting to create an array of numbers ranging from a specific minimum
value to a certain maximum
value with a specified decimal interval, such as 0.02. For instance, the sequence would be like: 1.00, 1.02, 1.04, 1.06
The issue arises when the code encounters the number 1.14
:
function getValues(minValue, maxValue, increment) {
var values = [];
for (var i = minValue; i <= maxValue; i += increment) {
values.push(i);
}
return values;
}
var values = getValues(1.0, 1.4, 0.02);
At this stage, the values
array appears as:
[
1,
1.02,
...
1.12,
1.1400000000000001,
1.1600000000000001
...
]
What is causing this discrepancy and what steps can I take to rectify it?