Home > Back-end >  Why data filtering does not work correctly?
Why data filtering does not work correctly?

Time:09-21

I am getting data from server and I want to filter it by data. I do it with if. But I ran into a problem, I get price data and compare it with my price data, but in the end they are wrong, for some reason the check does not pass, could you tell me what is the reason why the numbers are not compared correctly if I have an <= operator?

List speed = [
  7.4,
  11,
  22,
];

List<double> price = [
  0.20,
  0.25,
  0.30,
  0.35,
  0.40,
  0.45,
  0.50,
];


  if ((w.power.toInt() == speed[filters.minSpeed]) &&
              (double.parse(w.formattedPrice.substring(1)) <=
                  price[filters.maxPrice]) ||
          (i.public == filters.ownershipStationPublic ||
              filters.ownershipStationAll)) {
    log(double.parse(w.formattedPrice.substring(1)).toString());
    log('My price: ${price[filters.maxPrice].toString()}');
    filteredStations.add(i);
  }

CodePudding user response:

Even if the price is higher, the if statement is also true if either i.public == filters.ownershipStationPublic or filters.ownershipStationAll are true. Maybe this is happening here. Maybe you wanted that first || to be &&

  • Related