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

Commit

Permalink
Fix Thousand Separator format
Browse files Browse the repository at this point in the history
  • Loading branch information
Laifsyn committed Jun 8, 2024
1 parent d45d6bf commit 6aea9ad
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/main/java/com/utp/clsEstructuraDiscretas/pry4/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ void run_app() {
constraints.gridx = 0;
constraints.gridy++;
constraints.gridwidth = 2;
constraints.anchor = GridBagConstraints.EAST;
panel_final.add(resultado, constraints);

frame.add(panel_final);
Expand All @@ -108,22 +109,22 @@ void run_app() {
frame.setVisible(true);
}

// Thousand separated BigInteger
String pretty_big_int(BigInteger big_int) {
if (big_int.compareTo(BigInteger.valueOf(1000)) < 0) {
return String.valueOf(big_int);
}
// Thousand separated BigInteger
ArrayList<Integer> triplets = new ArrayList<>();

// 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));
}
StringBuilder builder = new StringBuilder();
builder.append(triplets.remove(0));
for (Integer triplet : triplets) {
builder.append(triplets.remove(triplets.size() - 1));
for (int i = triplets.size() - 1; i >= 0; i--) {
builder.append(",");
builder.append(String.format("%03d", triplet));
builder.append(String.format("%03d", triplets.get(i)));
}
return builder.toString();
}
Expand Down

0 comments on commit 6aea9ad

Please sign in to comment.