Skip to content

Commit

Permalink
Changed display from engineering to std string
Browse files Browse the repository at this point in the history
  • Loading branch information
frossm committed May 31, 2023
1 parent 6fffe73 commit bdea481
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 15 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

<groupId>org.fross</groupId>
<artifactId>rpncalc</artifactId>
<version>5.0.6</version>
<version>5.0.7</version>
<packaging>jar</packaging>

<name>rpncalc</name>
Expand Down
2 changes: 1 addition & 1 deletion snap/snapcraft.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: rpncalc
version: '5.0.6'
version: '5.0.7'
summary: The command line Reverse Polish Notation (RPN) calculator
description: |
RPNCalc is an easy to use command line based Reverse Polish
Expand Down
24 changes: 12 additions & 12 deletions src/main/java/org/fross/rpncalc/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -178,16 +178,16 @@ public static void main(String[] args) {
// Loop through the stack and count the max digits before the decimal for use with the decimal
// alignment mode & overall length for right alignment mode
for (int k = 0; k < calcStack.size(); k++) {
int decimalIndex = Format.Comma(calcStack.get(k).toPlainString()).indexOf(".");
int decimalIndex = Format.Comma(calcStack.get(k).toString()).indexOf(".");

// If current stack item has more digits ahead of decimal make that the max - commas are included.
if (maxDigitsBeforeDecimal < decimalIndex) {
maxDigitsBeforeDecimal = decimalIndex;
}

// Determine the length of the longest item in the stack for right alignment
if (Format.Comma(calcStack.get(k).toPlainString()).length() > maxLenOfNumbers) {
maxLenOfNumbers = Format.Comma(calcStack.get(k).toPlainString()).length();
if (Format.Comma(calcStack.get(k).toString()).length() > maxLenOfNumbers) {
maxLenOfNumbers = Format.Comma(calcStack.get(k).toString()).length();
}
}

Expand All @@ -207,12 +207,12 @@ public static void main(String[] args) {
int decimalLocation = 0;

// Put in spaces to align the decimals
if (calcStack.get(i).toEngineeringString().toLowerCase().contains("e")) {
stkLineNumber = calcStack.get(i).toEngineeringString();
if (calcStack.get(i).toString().toLowerCase().contains("e")) {
stkLineNumber = calcStack.get(i).toString();
decimalLocation = stkLineNumber.indexOf(".");

} else {
stkLineNumber = Format.Comma(calcStack.get(i).toEngineeringString());
stkLineNumber = Format.Comma(calcStack.get(i).toString());
decimalLocation = stkLineNumber.indexOf(".");
}

Expand All @@ -223,17 +223,17 @@ public static void main(String[] args) {

} else if (configAlignment.compareTo("r") == 0) {
// Right Alignment
if (calcStack.get(i).toEngineeringString().toLowerCase().contains("e"))
stkLineNumber = String.format("%" + maxLenOfNumbers + "s", calcStack.get(i).toEngineeringString());
if (calcStack.get(i).toString().toLowerCase().contains("e"))
stkLineNumber = String.format("%" + maxLenOfNumbers + "s", calcStack.get(i).toString());
else
stkLineNumber = String.format("%" + maxLenOfNumbers + "s", Format.Comma(calcStack.get(i).toEngineeringString()));
stkLineNumber = String.format("%" + maxLenOfNumbers + "s", Format.Comma(calcStack.get(i).toString()));

} else {
// Left Alignment
if (calcStack.get(i).toEngineeringString().toLowerCase().contains("e"))
stkLineNumber = calcStack.get(i).toEngineeringString();
if (calcStack.get(i).toString().toLowerCase().contains("e"))
stkLineNumber = calcStack.get(i).toString();
else
stkLineNumber = Format.Comma(calcStack.get(i).toEngineeringString());
stkLineNumber = Format.Comma(calcStack.get(i).toString());
}

// Finally display the current stack item after removing any spaces at the end
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/fross/rpncalc/StackObj.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public StackObj clone() throws CloneNotSupportedException {
* @return
*/
public String getAsString(int index) {
return this.get(index).toEngineeringString();
return this.get(index).toString();
}

/**
Expand Down

0 comments on commit bdea481

Please sign in to comment.