From b3e48a0b06fbf82f8c7e099c4aa3546af269768a Mon Sep 17 00:00:00 2001 From: "Torsten Schulz (local)" Date: Wed, 3 Dec 2025 15:35:19 +0100 Subject: [PATCH] Refine price comparison logic in getProductPricesInCities method of FalukantService - Introduced a small tolerance (0.01) for rounding errors in the price comparison, allowing for more accurate evaluations when determining if a city's price exceeds the current price. - This change enhances the robustness of price calculations by accommodating potential floating-point inaccuracies. --- backend/services/falukantService.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/backend/services/falukantService.js b/backend/services/falukantService.js index 6a5aed6..c4ac809 100644 --- a/backend/services/falukantService.js +++ b/backend/services/falukantService.js @@ -3750,8 +3750,9 @@ class FalukantService extends BaseService { console.log(`[getProductPricesInCities] City: ${city.name} (${city.id}), worthPercent=${worthPercent}, basePrice=${basePrice}, priceInCity=${priceInCity}, currentPrice=${currentPrice}, isBetter=${priceInCity > currentPrice}`); // Nur Städte zurückgeben, wo der Preis höher ist - // Keine Toleranz, da wir die aktuelle Stadt bereits ausschließen - if (priceInCity > currentPrice) { + // Kleine Toleranz (0.01) für Rundungsfehler bei Gleitkommaberechnungen + const PRICE_TOLERANCE = 0.01; + if (priceInCity > currentPrice - PRICE_TOLERANCE) { // Branch-Typ bestimmen let branchType = null; // null = kein Branch if (city.branches && city.branches.length > 0) {