check for NaN

This commit is contained in:
Denis Molony 2016-03-15 09:55:17 +11:00
parent 58d1804a97
commit a76861f3ae
2 changed files with 13 additions and 9 deletions

View File

@ -119,18 +119,19 @@ class Cell implements Comparable<Cell>, Value
case VALUE:
if (hasValue ())
{
Double value = getValue ();
if (Double.isNaN (value))
return justify ("", colWidth);
char format = cellFormat != ' ' ? cellFormat : defaultFormat;
if (format == 'I')
{
String integerFormat = String.format ("%%%d.0f", colWidth);
return String.format (integerFormat, getValue ());
return String.format (integerFormat, value);
}
else if (format == '$')
{
String currencyFormat = String.format ("%%%d.%ds", colWidth, colWidth);
Double value = getValue ();
if (Double.isNaN (value))
return justify ("", colWidth);
return String.format (currencyFormat, nf.format (value));
}
else if (format == '*')
@ -143,7 +144,7 @@ class Cell implements Comparable<Cell>, Value
{
// this could be improved
String numberFormat = String.format ("%%%d.3f", colWidth + 4);
String val = String.format (numberFormat, getValue ());
String val = String.format (numberFormat, value);
while (val.endsWith ("0"))
val = ' ' + val.substring (0, val.length () - 1);
if (val.endsWith ("."))

View File

@ -183,7 +183,7 @@ public class Sheet implements Iterable<Cell>
switch (line.charAt (1))
{
case 'W':
System.out.printf ("Skipping [%s]%n", line);
// System.out.printf ("Skipping [%s]%n", line);
break;
case 'G':
switch (line.charAt (2))
@ -195,7 +195,7 @@ public class Sheet implements Iterable<Cell>
recalculationOrder = line.charAt (3);
break;
case 'P':
System.out.printf ("Skipping [%s]%n", line);
// System.out.printf ("Skipping [%s]%n", line);
break;
case 'C':
columnWidth = Integer.parseInt (line.substring (3));
@ -209,7 +209,7 @@ public class Sheet implements Iterable<Cell>
}
break;
case 'X':
System.out.printf ("Skipping [%s]%n", line);
// System.out.printf ("Skipping [%s]%n", line);
break;
default:
System.out.printf ("Skipping [%s]%n", line);
@ -342,7 +342,7 @@ public class Sheet implements Iterable<Cell>
String underline = "---------------------------------------------------------"
+ "-----------------------------------------------------------------";
int lastRow = -1;
int lastRow = 0;
int lastColumn = 0;
StringBuilder heading = new StringBuilder (" ");
@ -365,7 +365,10 @@ public class Sheet implements Iterable<Cell>
}
if (debug)
{
text.append (heading);
text.append ("\n001:");
}
for (Cell cell : sheet.values ())
{