Skip to content

Commit

Permalink
Exponent parsing of negative number was incorrect.
Browse files Browse the repository at this point in the history
  • Loading branch information
Chrriis committed Nov 18, 2016
1 parent 8cab965 commit 717a62e
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion DJSwingSuite/src/chrriis/dj/swingsuite/JNumberEntryField.java
Expand Up @@ -168,6 +168,10 @@ public Number parseNumber(String text) {

public String formatNumber(Number number) {
String s = number.toString();
boolean isNegative = s.startsWith("-");
if(isNegative) {
s = s.substring(1);
}
int index = s.indexOf('E');
if(index >= 0) {
int exponent = Integer.parseInt(s.substring(index + 1));
Expand Down Expand Up @@ -196,7 +200,11 @@ public String formatNumber(Number number) {
if(s.endsWith(".0")) {
s = s.substring(0, s.length() - 2);
}
return s.replace('.', DECIMAL_SEPARATOR);
String value = s.replace('.', DECIMAL_SEPARATOR);
if(isNegative) {
value = "-" + value;
}
return value;
}

}
Expand Down

0 comments on commit 717a62e

Please sign in to comment.