mirror of
https://github.com/songoda/FabledSkyBlock.git
synced 2024-11-26 20:26:34 +01:00
Numbers using commas as decimal separator
This commit is contained in:
parent
1bc5e1fb6f
commit
17a0b30161
@ -1,6 +1,7 @@
|
|||||||
package me.goodandevil.skyblock.utils;
|
package me.goodandevil.skyblock.utils;
|
||||||
|
|
||||||
import java.text.DecimalFormat;
|
import java.text.DecimalFormat;
|
||||||
|
import java.text.NumberFormat;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
public final class NumberUtil {
|
public final class NumberUtil {
|
||||||
@ -10,14 +11,22 @@ public final class NumberUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static String formatNumberByDecimal(double number) {
|
public static String formatNumberByDecimal(double number) {
|
||||||
String withoutDecimal = new DecimalFormat("0.#").format(number), withDecimal = "";
|
DecimalFormat decimalFormat = new DecimalFormat("0.#");
|
||||||
|
String withoutDecimal = decimalFormat.format(number), withDecimal = "";
|
||||||
|
|
||||||
|
if (decimalFormat.getDecimalFormatSymbols().getDigit() == '.') {
|
||||||
if (withoutDecimal.contains(".")) {
|
if (withoutDecimal.contains(".")) {
|
||||||
withDecimal = "." + withoutDecimal.split("\\.")[1];
|
withDecimal = "." + withoutDecimal.split("\\.")[1];
|
||||||
withoutDecimal = withoutDecimal.replace(withDecimal, "");
|
withoutDecimal = withoutDecimal.replace(withDecimal, "");
|
||||||
}
|
}
|
||||||
|
} else if (decimalFormat.getDecimalFormatSymbols().getDigit() == ',') {
|
||||||
|
if (withoutDecimal.contains(",")) {
|
||||||
|
withDecimal = "," + withoutDecimal.split(",")[1];
|
||||||
|
withoutDecimal = withoutDecimal.replace(withDecimal, "");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (withDecimal.equals(".0")) {
|
if (withDecimal.equals(".0") || withDecimal.equals(",0")) {
|
||||||
withDecimal = "";
|
withDecimal = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user