utils
This commit is contained in:
parent
241feba114
commit
932a74dc42
4 changed files with 144 additions and 14 deletions
|
@ -0,0 +1,33 @@
|
|||
package me.unurled.sacredrealms.sr.utils;
|
||||
|
||||
public class NumberParser {
|
||||
public static double parse(String input) {
|
||||
input = input.toLowerCase().trim();
|
||||
double multiplier = 1.0;
|
||||
|
||||
if (input.endsWith("k")) {
|
||||
multiplier = 1e3;
|
||||
input = input.substring(0, input.length() - 1);
|
||||
} else if (input.endsWith("m")) {
|
||||
multiplier = 1e6;
|
||||
input = input.substring(0, input.length() - 1);
|
||||
} else if (input.endsWith("b")) {
|
||||
multiplier = 1e9;
|
||||
input = input.substring(0, input.length() - 1);
|
||||
}
|
||||
|
||||
return Double.parseDouble(input) * multiplier;
|
||||
}
|
||||
|
||||
public static String format(double number) {
|
||||
if (number >= 1e9) {
|
||||
return String.format("%.2fb", number / 1e9);
|
||||
} else if (number >= 1e6) {
|
||||
return String.format("%.2fm", number / 1e6);
|
||||
} else if (number >= 1e3) {
|
||||
return String.format("%.2fk", number / 1e3);
|
||||
} else {
|
||||
return String.format("%.2f", number);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue