From 0a12b224986065c1bd06879e6753bdad65ba3345 Mon Sep 17 00:00:00 2001 From: LemonNexus Date: Sun, 8 Feb 2026 23:28:44 +0000 Subject: [PATCH] fix(hud): fix Decimal/float division error in cost calculation - Convert both damage and dpp to Decimal before division - Proper Decimal arithmetic for precision --- ui/main_window.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/ui/main_window.py b/ui/main_window.py index dc4a626..d0d1936 100644 --- a/ui/main_window.py +++ b/ui/main_window.py @@ -1008,13 +1008,16 @@ class MainWindow(QMainWindow): # Estimate cost per shot based on weapon stats if self._selected_weapon_stats: - # Rough estimate: if we know DPP and damage, we can estimate cost dpp = self._selected_weapon_stats.get('dpp', 0) - if dpp > 0: + if dpp and dpp > 0: # Cost per shot in PEC = damage / DPP - cost_pec = damage / dpp - cost_ped = cost_pec / 100 # Convert to PED - self.hud.update_cost(Decimal(str(cost_ped))) + # Convert to Decimal for precision + from decimal import Decimal + damage_dec = Decimal(str(damage)) + dpp_dec = Decimal(str(dpp)) + cost_pec = damage_dec / dpp_dec + cost_ped = cost_pec / Decimal('100') # Convert to PED + self.hud.update_cost(cost_ped) def on_critical_hit(event): """Handle critical hit - same as damage dealt."""