Fix numeric overflow

Make multiplication cumulative (handy since it's already a switch case)
Convert and use uppercase

Also remove unused statusIsOK method, or as Clou calls it, dead code
This commit is contained in:
DaCool
2023-10-01 16:30:02 +00:00
committed by Sheepit Renderfarm
parent 6d050d7fd9
commit e99d1fa668

View File

@@ -255,23 +255,16 @@ public class Utils {
}
final Matcher m = Pattern.compile("([\\d.,]+)\\s*(\\w)").matcher(in);
m.find();
int scale = 1;
switch (m.group(2).charAt(0)) {
long scale = 1;
switch (Character.toUpperCase(m.group(2).charAt(0))) {
case 'T':
case 't':
scale = 1000 * 1000 * 1000 * 1000;
break;
case 'G':
case 'g':
scale = 1000 * 1000 * 1000;
break;
scale *= 1000; //Multiply by 1000 each time the higher the metric prefix
case 'G': //Note the lack of break statements, thus it executes through
scale *= 1000;
case 'M':
case 'm':
scale = 1000 * 1000;
break;
scale *= 1000;
case 'K':
case 'k':
scale = 1000;
scale *= 1000;
break;
}
return Math.round(Double.parseDouble(m.group(1)) * scale);