From 065291e14697d6b09143f0bea1acaf9e325df8c3 Mon Sep 17 00:00:00 2001 From: "DESKTOP-T0O5CDB\\DESK-555BD" Date: Sun, 1 Sep 2024 11:02:04 -0600 Subject: [PATCH] Fix divide by zero error in Cost Per Mile metric --- Controllers/HomeController.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Controllers/HomeController.cs b/Controllers/HomeController.cs index c406da6..d309c9c 100644 --- a/Controllers/HomeController.cs +++ b/Controllers/HomeController.cs @@ -93,7 +93,7 @@ namespace CarCareTracker.Controllers var maxMileage = _vehicleLogic.GetMaxMileage(vehicleRecords); var minMileage = _vehicleLogic.GetMinMileage(vehicleRecords); var totalDistance = maxMileage - minMileage; - vehicleVM.CostPerMile = vehicleTotalCost / totalDistance; + vehicleVM.CostPerMile = totalDistance != default ? vehicleTotalCost / totalDistance : 0.00M; vehicleVM.DistanceUnit = distanceUnit; } if (vehicleVM.DashboardMetrics.Contains(DashboardMetric.TotalCost))