Skip to content
This repository has been archived by the owner on Aug 9, 2024. It is now read-only.

Commit

Permalink
Improve Beautified BigInt
Browse files Browse the repository at this point in the history
  • Loading branch information
Laifsyn committed Jun 9, 2024
1 parent a493669 commit 8fa236d
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/main/java/com/utp/clsEstructuraDiscretas/pry4/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -115,17 +115,25 @@ String pretty_big_int(BigInteger big_int) {
return String.valueOf(big_int);
}
ArrayList<Integer> triplets = new ArrayList<>();
BigInteger acc = big_int;
// Insertar Triplets en LowEndian
while (big_int.compareTo(BigInteger.ZERO) > 0) {
triplets.add(big_int.mod(BigInteger.valueOf(1000)).intValue());
big_int = big_int.divide(BigInteger.valueOf(1000));
while (acc.compareTo(BigInteger.ZERO) > 0) {
triplets.add(acc.mod(BigInteger.valueOf(1000)).intValue());
acc = acc.divide(BigInteger.valueOf(1000));
}
StringBuilder builder = new StringBuilder();
builder.append(triplets.remove(triplets.size() - 1));
for (int i = triplets.size() - 1; i >= 0; i--) {
builder.append(",");
builder.append(String.format("%03d", triplets.get(i)));
}
String bigint_string = big_int.toString();
final int MAX_LENGTH = 20 * 3;
if (bigint_string.length() >= MAX_LENGTH) {
String substring = builder.toString().substring(0, MAX_LENGTH);
int commas = substring.length() - substring.replace(",", "").length();
return substring + "...+" + (commas + bigint_string.length() - MAX_LENGTH);
}
return builder.toString();
}

Expand Down

0 comments on commit 8fa236d

Please sign in to comment.