WIP
This commit is contained in:
@@ -54,12 +54,12 @@ public final class GajuFormat {
|
||||
String gajuStr = chunkString(divRem[0].toString(), spec.separator(), spec.span(), false);
|
||||
String sign = isNegative ? "-" : "";
|
||||
String head = GAJU_MARK + sign + gajuStr;
|
||||
|
||||
|
||||
String puckFull = String.format("%018d", divRem[1]);
|
||||
int prec = Math.min(precision, FRACTION_LEN);
|
||||
String significant = puckFull.substring(0, prec);
|
||||
String rest = puckFull.substring(prec);
|
||||
|
||||
|
||||
boolean hasMore = false;
|
||||
for (int i = 0; i < rest.length(); i++) {
|
||||
if (rest.charAt(i) != '0') {
|
||||
@@ -67,12 +67,12 @@ public final class GajuFormat {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
String resultTail = cleanTrailingZeros(significant);
|
||||
if (resultTail.isEmpty()) {
|
||||
return hasMore ? head + "...." : head;
|
||||
}
|
||||
|
||||
|
||||
return head + "." + chunkString(resultTail, spec.separator(), spec.span(), true) + (hasMore ? "..." : "");
|
||||
}
|
||||
|
||||
@@ -101,9 +101,9 @@ public final class GajuFormat {
|
||||
|
||||
BigInteger[] divRem = absPucks.divideAndRemainder(ONE_GAJU);
|
||||
String gajuFormatted = processRanks(divRem[0], ranks, 4, GAJU_MARK, false);
|
||||
|
||||
|
||||
if (divRem[1].equals(BigInteger.ZERO)) return sign + gajuFormatted;
|
||||
|
||||
|
||||
return sign + gajuFormatted + " " + processRanks(divRem[1], ranks, 4, PUCK_MARK, false);
|
||||
}
|
||||
|
||||
@@ -115,9 +115,9 @@ public final class GajuFormat {
|
||||
|
||||
BigInteger[] divRem = absPucks.divideAndRemainder(ONE_GAJU);
|
||||
String gajuPart = GAJU_MARK + sign + processRanks(divRem[0], ranks, 3, gSuffix, true);
|
||||
|
||||
|
||||
if (divRem[1].equals(BigInteger.ZERO)) return gajuPart;
|
||||
|
||||
|
||||
return gajuPart + " " + processRanks(divRem[1], ranks, 3, pSuffix, true);
|
||||
}
|
||||
|
||||
@@ -148,11 +148,11 @@ public final class GajuFormat {
|
||||
|
||||
private static String processRanks(BigInteger value, String[] ranks, int span, String endingSymbol, boolean useSpaces) {
|
||||
if (value.equals(BigInteger.ZERO)) return "0" + (useSpaces ? " " : "") + endingSymbol;
|
||||
|
||||
|
||||
StringBuilder result = new StringBuilder();
|
||||
BigInteger divisor = BigInteger.TEN.pow(span);
|
||||
int rankIndex = 0;
|
||||
|
||||
|
||||
BigInteger current = value;
|
||||
while (current.compareTo(BigInteger.ZERO) > 0) {
|
||||
BigInteger[] dr = current.divideAndRemainder(divisor);
|
||||
@@ -164,7 +164,7 @@ public final class GajuFormat {
|
||||
current = dr[0];
|
||||
rankIndex++;
|
||||
}
|
||||
|
||||
|
||||
String res = result.toString().trim();
|
||||
return res + (useSpaces ? " " : "") + endingSymbol;
|
||||
}
|
||||
@@ -216,23 +216,23 @@ public final class GajuFormat {
|
||||
|
||||
BigInteger gajuTotal = BigInteger.ZERO;
|
||||
BigInteger puckTotal = BigInteger.ZERO;
|
||||
|
||||
|
||||
if (input.contains(".")) {
|
||||
int dotIdx = input.indexOf('.');
|
||||
String gajuPart = input.substring(0, dotIdx);
|
||||
String puckPart = input.substring(dotIdx + 1);
|
||||
|
||||
|
||||
BigInteger gVal = parseRawRanked(gajuPart);
|
||||
StringBuilder sb = new StringBuilder(puckPart);
|
||||
while (sb.length() < FRACTION_LEN) sb.append('0');
|
||||
if (sb.length() > FRACTION_LEN) throw new IllegalArgumentException("Precision overflow");
|
||||
BigInteger pVal = new BigInteger(sb.toString());
|
||||
|
||||
|
||||
puckTotal = gVal.multiply(ONE_GAJU).add(pVal);
|
||||
} else {
|
||||
boolean treatAsGaju = !forcePuck;
|
||||
StringBuilder digits = new StringBuilder();
|
||||
|
||||
|
||||
for (int i = 0; i < input.length(); i++) {
|
||||
char c = input.charAt(i);
|
||||
if (Character.isDigit(c)) {
|
||||
@@ -285,7 +285,7 @@ public final class GajuFormat {
|
||||
private static BigInteger parseRawRanked(String input) {
|
||||
BigInteger total = BigInteger.ZERO;
|
||||
StringBuilder currentDigits = new StringBuilder();
|
||||
|
||||
|
||||
for (int i = 0; i < input.length(); i++) {
|
||||
char c = input.charAt(i);
|
||||
if (Character.isDigit(c)) {
|
||||
|
||||
Reference in New Issue
Block a user