Skip to content

Commit

Permalink
Fix Negative value and range Bug
Browse files Browse the repository at this point in the history
  • Loading branch information
Gruzer committed Feb 9, 2021
1 parent d4b9f9b commit 52a4516
Showing 1 changed file with 14 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,6 @@ protected int getCalculateValuePercentage(double min, double max, double value)
} else if (min < max) {
return getCalculateValuePercentageUseCaseFoure(min, max, value);
}

}
return getCalculateValuePercentageOld(min, max, value);
}
Expand All @@ -206,10 +205,10 @@ private int getCalculateValuePercentageUseCaseOne(double min, double max, double
if (value >= Math.max(min, max))
return 100;
else {
double avalibe = Math.abs(Math.min(min, max)) - Math.abs(Math.max(min, max));
double available = Math.abs(Math.min(min, max)) - Math.abs(Math.max(min, max));
double minValue = Math.min(min, max);
double reult = Math.abs(((minValue - value) / (avalibe) * 100));
return (int) reult;
double result = Math.abs(((minValue - value) / (available) * 100));
return (int) result;
}
}

Expand All @@ -223,10 +222,10 @@ private int getCalculateValuePercentageUseCaseTwo(double min, double max, double
if (value >= Math.max(min, max))
return 0;
else {
double avalibe = Math.abs(Math.min(min, max)) - Math.abs(Math.max(min, max));
double available = Math.abs(Math.min(min, max)) - Math.abs(Math.max(min, max));
double maxValue = Math.max(min, max);
double reult = Math.abs(((maxValue - value) / (avalibe) * 100));
return (int) reult;
double result = Math.abs(((maxValue - value) / (available) * 100));
return (int) result;
}
}

Expand All @@ -238,19 +237,15 @@ private int getCalculateValuePercentageUseCaseTwo(double min, double max, double
* TODO: Need Improvements
*/
private int getCalculateValuePercentageUseCaseThree(double min, double max, double value) {
double avalibe = Math.abs(min) + Math.abs(max);
double available = Math.abs(min) + Math.abs(max);
if (value <= Math.min(min, max)) {
return 100;
} else if (value >= Math.max(min, max))
return 0;
else if (value <= 0) {
else{
double positive = Math.max(min, max);
double reult = ((positive - value) / (avalibe) * 100);
return (int) reult;
} else {
double negative = Math.abs(Math.min(min, max));
double reult = Math.abs((negative + value) / (avalibe) * 100);
return (int) reult;
double result = Math.abs((positive - value) / (available) * 100);
return (int) result;
}
}

Expand All @@ -260,19 +255,15 @@ else if (value <= 0) {
* TODO: Need Improvements
*/
private int getCalculateValuePercentageUseCaseFoure(double min, double max, double value) {
double avalibe = Math.abs(min) + Math.abs(max);
double available = Math.abs(min) + Math.abs(max);
if (value <= Math.min(min, max)) {
return 0;
} else if (value >= Math.max(min, max))
return 100;
else if (value >= 0) {
double positive = Math.max(min, max);
double reult = ((positive + value) / (avalibe) * 100);
return (int) reult;
} else {
else{
double negative = Math.abs(Math.min(min, max));
double reult = Math.abs((negative + value) / (avalibe) * 100);
return (int) reult;
double result = Math.abs((negative + value) / (available) * 100);
return (int) result;
}
}

Expand Down

0 comments on commit 52a4516

Please sign in to comment.