[github-281] Thanks to This closes #281

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1895284 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
PJ Fanning 2021-11-24 09:55:33 +00:00
parent aa92a67baf
commit 7b02f24e47
2 changed files with 20 additions and 1 deletions

View File

@ -29,6 +29,7 @@ import java.util.regex.Pattern;
import javax.swing.JLabel;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.ITestDataProvider;
import org.apache.poi.ss.format.CellFormat;
import org.apache.poi.ss.format.CellFormatPart;
@ -217,4 +218,22 @@ class TestCellFormatPart {
}
}
}
@Test
void testDecimalFormat() throws Exception {
// Create a workbook, row and cell to test with
try (Workbook wb = new HSSFWorkbook()) {
Sheet sheet = wb.createSheet();
Row row = sheet.createRow(0);
Cell cell = row.createCell(0);
CellFormat cf = CellFormat.getInstance("[<=.01]0.00%;#,##0");
cell.setCellValue(1);
assertEquals("1", cf.apply(cell).text);
cell.setCellValue(.001);
assertEquals("0.10%", cf.apply(cell).text);
}
}
}

View File

@ -104,7 +104,7 @@ public class CellFormatPart {
static {
// A condition specification
String condition = "([<>=]=?|!=|<>) # The operator\n" +
" \\s*(-?[0-9]+(?:\\.[0-9]*)?)\\s* # The constant to test against\n";
" \\s*(-?([0-9]+(?:\\.[0-9]*)?)|(\\.[0-9]*))\\s* # The constant to test against\n";;
// A currency symbol / string, in a specific locale
String currency = "(\\[\\$.{0,3}(-[0-9a-f]{3,4})?\\])";