🔢 added space separator for numbers

Took 21 seconds
This commit is contained in:
Kiran Hart 2024-01-23 14:40:43 -05:00
parent b76caa6c1f
commit 5e603d7c79
No known key found for this signature in database
GPG Key ID: 5F36C7BC79D3EBC3
2 changed files with 33 additions and 1 deletions

View File

@ -380,7 +380,9 @@ public class AuctionAPI {
* @return the formatted number string
*/
public String formatNumber(double number) {
String formatted = String.format(Settings.CURRENCY_FORMAT.getString(), number);
String formatted = String.format(Settings.CURRENCY_FORMAT.getString(), number);//%,.2f
if (Settings.USE_SPACE_SEPARATOR_FOR_NUMBER.getBoolean())
formatted = formatted.replace(",", " ");
// do the zero drop here
// this is a bit scuffed, I gotta improve this
@ -411,6 +413,35 @@ public class AuctionAPI {
return string.substring(0, index) + replacement + string.substring(index + substring.length());
}
public static String replaceAllExceptLast(String input, char target, char replacement) {
int lastIndex = input.lastIndexOf(target);
if (lastIndex == -1) {
// If the target character is not found, return the original string
return input;
}
StringBuilder result = new StringBuilder();
boolean foundLast = false;
for (int i = 0; i < input.length(); i++) {
char currentChar = input.charAt(i);
if (currentChar == target && i == lastIndex && !foundLast) {
// Keep the last instance unchanged
result.append(currentChar);
foundLast = true;
} else if (currentChar == target) {
// Replace all instances except the last one
result.append(replacement);
} else {
result.append(currentChar);
}
}
return result.toString();
}
/**
* Used to get command flags (ex. -h, -f, -t, etc)
*

View File

@ -160,6 +160,7 @@ public class Settings {
public static final ConfigSetting USE_ALTERNATE_CURRENCY_FORMAT = new ConfigSetting(config, "auction setting.use alternate currency format", false, "If true, $123,456.78 will become $123.456,78");
public static final ConfigSetting USE_FLAT_NUMBER_FORMAT = new ConfigSetting(config, "auction setting.use flat number format", false, "If true, $123,456.78 will become $12345678");
public static final ConfigSetting USE_SPACE_SEPARATOR_FOR_NUMBER = new ConfigSetting(config, "auction setting.use space separator for number", false, "If true, $123,456.78 will become $123 456.78");
public static final ConfigSetting DATE_FORMAT = new ConfigSetting(config, "auction setting.date format", "MMM dd, yyyy hh:mm aa", "You can learn more about date formats by googling SimpleDateFormat patterns or visiting this link", "https://docs.oracle.com/javase/7/docs/api/java/text/SimpleDateFormat.html");
public static final ConfigSetting ALLOW_PLAYERS_TO_ACCEPT_BID = new ConfigSetting(config, "auction setting.allow players to accept bid", true, "If true, players can right click a biddable item inside their active listings menu to accept the current bid");
public static final ConfigSetting SELLERS_MUST_WAIT_FOR_TIME_LIMIT_AFTER_BID = new ConfigSetting(config, "auction setting.prevent cancellation of bid on items", false, "If true, players must wait out the duration of the auction listing if there is already a bid on it (makes them commit to selling it)");