Use a round method that does NOT crash when the computer's language uses commas as delimiter for floating point numbers (yes, German computers had a crash there)
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
package eu.crushedpixel.replaymod.utils;
|
package eu.crushedpixel.replaymod.utils;
|
||||||
|
|
||||||
import java.text.DecimalFormat;
|
import java.math.BigDecimal;
|
||||||
|
import java.math.RoundingMode;
|
||||||
|
|
||||||
public class RoundUtils {
|
public class RoundUtils {
|
||||||
|
|
||||||
@@ -15,13 +16,9 @@ public class RoundUtils {
|
|||||||
public static double round(double value, int places) {
|
public static double round(double value, int places) {
|
||||||
if (places < 0) throw new IllegalArgumentException();
|
if (places < 0) throw new IllegalArgumentException();
|
||||||
|
|
||||||
StringBuilder format = new StringBuilder("#.");
|
BigDecimal bd = new BigDecimal(value);
|
||||||
for(int i=0; i<places; i++) {
|
bd = bd.setScale(places, RoundingMode.HALF_UP);
|
||||||
format.append("#");
|
return bd.doubleValue();
|
||||||
}
|
|
||||||
|
|
||||||
DecimalFormat df = new DecimalFormat(format.toString());
|
|
||||||
return Double.valueOf(df.format(value));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int getClosestInt(int base, int[] snap) {
|
public static int getClosestInt(int base, int[] snap) {
|
||||||
|
|||||||
Reference in New Issue
Block a user