I am aiming to find all combinations of a 4 digit number among the given values. But even though I set .1 increment in json it is increasing .09999999. This increment error occurs after step 2. No way could I solve it. Can anyone see where I am wrong in the code below? Have something to add?
window.onload = ()=>{
class playSearch {
createCombination(arr) {
/*
ppp => i
atr-f => f
atr-p => p
*/
this.combination = [];
for (let i = arr[0].min; i <= arr[0].max; i = i + arr[0].plus) {
for (let f = arr[1].min; f <= arr[1].max; f = (f + arr[1].plus)) {
console.log(arr[1].plus)
console.log(f)
for (let p = arr[2].min; p <= arr[2].max; p=p+arr[2].plus) {
for (let m = arr[3].min; m <= arr[3].max; m=m+arr[3].plus) {
this.combination.push([i,f,p,m])
}
}
}
}
}
}
var user = new playSearch();
user.createCombination(
[
{
"name": "ppp",
"min": 1,
"max": 11,
"plus": 1
},
{
"name": "atr-f",
"min":10,
"max":20,
"plus":1/10
},
{
"name":"atr-p",
"min":1,
"max":5,
"plus":1
},
{
"name":"min-profit",
"min":1,
"max":5,
"plus":1
}
]
)
}
I couldn't understand why .0999 was added even though I added .1. The plus in the json determines the amount of increase. I'm waiting for your help.