Merge branch 'Utils-fixes' into 'master'
Fix numeric overflow See merge request sheepitrenderfarm/client!247
This commit is contained in:
@@ -255,23 +255,16 @@ public class Utils {
|
|||||||
}
|
}
|
||||||
final Matcher m = Pattern.compile("([\\d.,]+)\\s*(\\w)").matcher(in);
|
final Matcher m = Pattern.compile("([\\d.,]+)\\s*(\\w)").matcher(in);
|
||||||
m.find();
|
m.find();
|
||||||
int scale = 1;
|
long scale = 1;
|
||||||
switch (m.group(2).charAt(0)) {
|
switch (Character.toUpperCase(m.group(2).charAt(0))) {
|
||||||
case 'T':
|
case 'T':
|
||||||
case 't':
|
scale *= 1000; //Multiply by 1000 each time the higher the metric prefix
|
||||||
scale = 1000 * 1000 * 1000 * 1000;
|
case 'G': //Note the lack of break statements, thus it executes through
|
||||||
break;
|
scale *= 1000;
|
||||||
case 'G':
|
|
||||||
case 'g':
|
|
||||||
scale = 1000 * 1000 * 1000;
|
|
||||||
break;
|
|
||||||
case 'M':
|
case 'M':
|
||||||
case 'm':
|
scale *= 1000;
|
||||||
scale = 1000 * 1000;
|
|
||||||
break;
|
|
||||||
case 'K':
|
case 'K':
|
||||||
case 'k':
|
scale *= 1000;
|
||||||
scale = 1000;
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return Math.round(Double.parseDouble(m.group(1)) * scale);
|
return Math.round(Double.parseDouble(m.group(1)) * scale);
|
||||||
|
|||||||
Reference in New Issue
Block a user