Skip to content

Commit

Permalink
Fixed issue where ShortenJ would only parse the first part of numbers.
Browse files Browse the repository at this point in the history
  • Loading branch information
creatorfromhell committed Sep 21, 2024
1 parent 1c1509d commit e0cf9e0
Showing 1 changed file with 41 additions and 10 deletions.
51 changes: 41 additions & 10 deletions Core/src/net/tnemc/core/currency/format/impl/ShortenJRule.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
*/
public class ShortenJRule implements FormatRule {

private final BigInteger threshold = new BigInteger("9999");

@Override
public String name() {
return "<shortenj>";
Expand Down Expand Up @@ -65,37 +67,66 @@ public String format(@Nullable Account account, HoldingsEntry entry, String form
return format.replace("<short.amount>", monetaryMajor);
}

final int strLength = monetaryMajor.length() - 1;
String working = monetaryMajor;
final StringBuilder builder = new StringBuilder();
while(!working.isBlank() && new BigInteger(working).compareTo(new BigInteger("9999")) > 0) {

working = build(currency.get(), working, builder);
}
builder.append(working);

return format.replace("<short.amount>", builder.toString());
}

private String build(final Currency currency, String working, final StringBuilder builder) {
final int strLength = working.length() - 1;
final int multiple = (strLength / 4) * 4;
final int majorKeep = strLength % 4;
final int symbol = multiple / 4;

final StringBuilder workingBuilder = new StringBuilder();

char pre;
if(currency.get().getPrefixesj().length() < (symbol)) {
if(currency.getPrefixesj().length() < (symbol)) {
pre = '^';
} else {
pre = currency.get().getPrefixesj().charAt(symbol - 1);
pre = currency.getPrefixesj().charAt(symbol - 1);
}

final StringBuilder builder = new StringBuilder();
for(int i = 0; i < monetaryMajor.length(); i++) {
for(int i = 0; i < working.length(); i++) {

if(i > majorKeep) {

if(i == majorKeep + 1) {
builder.append(pre);
}

if(monetaryMajor.charAt(i) != '0') {
builder.append(monetaryMajor.substring(i));
if(working.charAt(i) != '0') {

workingBuilder.append(working.substring(i));
break;
}
continue;
}
builder.append(monetaryMajor.charAt(i));

builder.append(working.charAt(i));
}
return format.replace("<short.amount>", builder.toString());
return workingBuilder.toString();

/*for(int i = 0; i < working.length(); i++) {
if(i > majorKeep) {
if(i == majorKeep + 1) {
builder.append(pre);
}
if(working.charAt(i) != '0') {
builder.append(working.substring(i));
break;
}
continue;
}
builder.append(working.charAt(i));
}*/
}
}

0 comments on commit e0cf9e0

Please sign in to comment.