From d153836d6f9ffdb3d3490ed8081ea6e2ec50e1ec Mon Sep 17 00:00:00 2001 From: Paul Bellchambers Date: Thu, 22 Mar 2012 17:36:36 +0000 Subject: [PATCH] Divide by zero error fixed. --- .../WineBrewDB/Ledger/LedgerEquipmentPanel.java | 2 +- .../src/com/pori/WineBrewDB/SQLite/DBEngine.java | 14 ++++++++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/winebrewdb/src/com/pori/WineBrewDB/Ledger/LedgerEquipmentPanel.java b/winebrewdb/src/com/pori/WineBrewDB/Ledger/LedgerEquipmentPanel.java index 1bb1a7c..54c3545 100644 --- a/winebrewdb/src/com/pori/WineBrewDB/Ledger/LedgerEquipmentPanel.java +++ b/winebrewdb/src/com/pori/WineBrewDB/Ledger/LedgerEquipmentPanel.java @@ -572,7 +572,7 @@ public static void setLedgerEquipmentCostData(){ } } - //TODO: Fix divide by zero error + public static void setBrewTotalCostData(){ BigDecimal total = new BigDecimal("0"); for (int i = 0; i < (LedgerEquipmentCostTable.getRowCount()); i++ ) { diff --git a/winebrewdb/src/com/pori/WineBrewDB/SQLite/DBEngine.java b/winebrewdb/src/com/pori/WineBrewDB/SQLite/DBEngine.java index 78fd63c..acbaa40 100644 --- a/winebrewdb/src/com/pori/WineBrewDB/SQLite/DBEngine.java +++ b/winebrewdb/src/com/pori/WineBrewDB/SQLite/DBEngine.java @@ -1472,14 +1472,19 @@ public static BigDecimal getTotalNumberBrews() throws Exception { ResultSet rs = pre.executeQuery(); int NumberBrews = 0; + BigDecimal DecimalNumberBrews = new BigDecimal("0"); while(rs.next()){ //Add one to the current highest NumberBrews = rs.getInt(1); } - BigDecimal DecimalNumberBrews = new BigDecimal(NumberBrews); + if(NumberBrews == 0){ + DecimalNumberBrews = new BigDecimal("0.00000001"); + }else{ + DecimalNumberBrews = new BigDecimal(NumberBrews); + } /*Close the connection after use (MUST)*/ if(conn!=null) @@ -1501,14 +1506,19 @@ public static BigDecimal getTotalNumberBottles() throws Exception { ResultSet rs = pre.executeQuery(); int NumberBottles = 0; + BigDecimal DecimalNumberBottles = new BigDecimal("0"); while(rs.next()){ //Add one to the current highest NumberBottles = rs.getInt(1); } - BigDecimal DecimalNumberBottles = new BigDecimal(NumberBottles); + if(NumberBottles == 0){ + DecimalNumberBottles = new BigDecimal("0.00000001"); + }else{ + DecimalNumberBottles = new BigDecimal(NumberBottles); + } /*Close the connection after use (MUST)*/ if(conn!=null)