Skip to content

Commit

Permalink
Merge pull request #3047 from bitzesty/round
Browse files Browse the repository at this point in the history
fix: Handle division by zero in growth calculation
  • Loading branch information
matthewford authored Aug 21, 2024
2 parents e8577e3 + 739d540 commit 8312750
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 8312750

Please sign in to comment.