mirror of
https://github.com/SlimeVR/SlimeVR-Server.git
synced 2026-11-20 00:51:20 -08:00
Merge remote-tracking branch 'gui/main' into merge-gui-and-server
This commit is contained in:
commit
ae94de39b1
430 files changed
+44297
-50
No files matched your search
@@ -0,0 +1,35 @@
|
||||
package io.eiren.util;
|
||||
|
||||
import java.text.DecimalFormatSymbols;
|
||||
import java.util.Locale;
|
||||
|
||||
|
||||
public class StringUtils {
|
||||
|
||||
private static char DECIMAL_SEP;
|
||||
|
||||
public static char getDecimalSeparator() {
|
||||
if (DECIMAL_SEP == '\u0000') {
|
||||
final Locale l = Locale.getDefault(Locale.Category.FORMAT);
|
||||
// Formatter.java always use "." in the Locale.US
|
||||
DECIMAL_SEP = (l == null || l.equals(Locale.US)
|
||||
? '.'
|
||||
: DecimalFormatSymbols.getInstance(l).getDecimalSeparator());
|
||||
}
|
||||
return DECIMAL_SEP;
|
||||
}
|
||||
|
||||
public static String prettyNumber(float f) {
|
||||
return prettyNumber(f, 4);
|
||||
}
|
||||
|
||||
public static String prettyNumber(float f, int numDigits) {
|
||||
String str = String.format("%." + numDigits + "f", f);
|
||||
if (numDigits != 0)
|
||||
str = org.apache.commons.lang3.StringUtils.stripEnd(str, "0");
|
||||
char lastChar = str.charAt(str.length() - 1);
|
||||
if (lastChar == getDecimalSeparator())
|
||||
str = str.substring(0, str.length() - 1);
|
||||
return str;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user