String formatStr = formatStrIn;
- // Excel supports 3+ part conditional data formats, eg positive/negative/zero,
+ // Excel supports 2+ part conditional data formats, eg positive/negative/zero,
// or (>1000),(>0),(0),(negative). As Java doesn't handle these kinds
// of different formats for different ranges, just +ve/-ve, we need to
// handle these ourselves in a special way.
- // For now, if we detect 3+ parts, we call out to CellFormat to handle it
+ // For now, if we detect 2+ parts, we call out to CellFormat to handle it
// TODO Going forward, we should really merge the logic between the two classes
- if (formatStr.contains(";") &&
- formatStr.indexOf(';') != formatStr.lastIndexOf(';')) {
+ if (formatStr.contains(";") ) {
try {
// Ask CellFormat to get a formatter for it
CellFormat cfmt = CellFormat.getInstance(formatStr);
);
}
}
+
+ @Test
+ public void testConditionalRanges() {
+ DataFormatter dfUS = new DataFormatter(Locale.US);
+
+ String format = "[>=10]#,##0;[<10]0.0";
+ assertEquals("Wrong format for " + format, "17,876", dfUS.formatRawCellContents(17876.000, -1, format));
+ assertEquals("Wrong format for " + format, "9.7", dfUS.formatRawCellContents(9.71, -1, format));
+ }
/**
* Test how we handle negative and zeros.
//assertEquals("123", dfUS.formatRawCellContents(-123.321, -1, "0 ?/?;0"));
//Bug54868 patch has a hit on the first string before the ";"
- assertEquals("-123 1/3", dfUS.formatRawCellContents(-123.321, -1, "0 ?/?;0"));
+ assertEquals("123", dfUS.formatRawCellContents(-123.321, -1, "0 ?/?;0"));
+ assertEquals("123 1/3", dfUS.formatRawCellContents(123.321, -1, "0 ?/?;0"));
//Bug53150 formatting a whole number with fractions should just give the number
assertEquals("1", dfUS.formatRawCellContents(1.0, -1, "# #/#"));