Skip to content

Commit

Permalink
feat: Handle division by zero in growth calculation
Browse files Browse the repository at this point in the history
This commit modifies the `FinancialTableSummary` module to handle division by zero in the growth calculation. Previously, if the previous value was zero, the calculation would result in an error. Now, if the previous value is zero, the growth percentage is set to "-" to indicate no growth. This prevents the division by zero error and ensures accurate growth calculations.

```

Signed-off-by: Louis Kirkham <[email protected]>
  • Loading branch information
TheDancingClown committed Aug 21, 2024
1 parent e8577e3 commit 739d540
Showing 1 changed file with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -420,8 +420,12 @@ def fs_calculate_growth(values)
growth_percentages = ["-"]

(1...values.length).each do |i|
growth = ((values[i] - values[i - 1]) / values[i - 1]) * 100
growth_percentages << growth.round.to_s
if values[i - 1] != 0
growth = ((values[i] - values[i - 1]) / values[i - 1]) * 100
growth_percentages << growth.round.to_s
else
growth_percentages << "-" # Handle division by zero
end
end

growth_percentages
Expand Down

0 comments on commit 739d540

Please sign in to comment.