Skip to content

Commit

Permalink
refactor: handle edge cases better
Browse files Browse the repository at this point in the history
  • Loading branch information
setchy committed Jan 30, 2024
1 parent 2d71d49 commit a70c1f7
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions src/shared/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -410,19 +410,17 @@ $common.valueWithDefault = function valueWithDefault(variable, defaultValue) {
* function will return a percentage rounded to the tenth decimal place.
*/
$common.calcProgressPercent = function calcProgressPercent(total, completed) {
if (completed >= total) {
if (total == 0 || completed == 0) {
// the absence of work does not imply progress.
return 0;
} else if (completed >= total) {
// In something has already been completed (e.g. suppressed) and the completed value
// is greater than the total, return 100%
return 100;
} else if (total > 0) {
if (completed === 0) {
return 0;
} else {
let percentage = (completed / total) * 100;
return Math.round(percentage * 10) / 10;
}
}
return 0; // the absence of work does not imply progress.

let percentage = (completed / total) * 100;
return Math.round(percentage * 10) / 10;
};

/**
Expand Down

0 comments on commit a70c1f7

Please sign in to comment.