You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by fa...@apache.org on 2021/11/24 09:55:34 UTC
svn commit: r1895284 - in /poi/trunk: poi-ooxml/src/test/java/org/apache/poi/ss/tests/format/TestCellFormatPart.java poi/src/main/java/org/apache/poi/ss/format/CellFormatPart.java
Author: fanningpj
Date: Wed Nov 24 09:55:33 2021
New Revision: 1895284
URL: http://svn.apache.org/viewvc?rev=1895284&view=rev
Log:
[github-281] Thanks to This closes #281
Modified:
poi/trunk/poi-ooxml/src/test/java/org/apache/poi/ss/tests/format/TestCellFormatPart.java
poi/trunk/poi/src/main/java/org/apache/poi/ss/format/CellFormatPart.java
Modified: poi/trunk/poi-ooxml/src/test/java/org/apache/poi/ss/tests/format/TestCellFormatPart.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi-ooxml/src/test/java/org/apache/poi/ss/tests/format/TestCellFormatPart.java?rev=1895284&r1=1895283&r2=1895284&view=diff
==============================================================================
--- poi/trunk/poi-ooxml/src/test/java/org/apache/poi/ss/tests/format/TestCellFormatPart.java (original)
+++ poi/trunk/poi-ooxml/src/test/java/org/apache/poi/ss/tests/format/TestCellFormatPart.java Wed Nov 24 09:55:33 2021
@@ -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);
+ }
+ }
}
Modified: poi/trunk/poi/src/main/java/org/apache/poi/ss/format/CellFormatPart.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi/src/main/java/org/apache/poi/ss/format/CellFormatPart.java?rev=1895284&r1=1895283&r2=1895284&view=diff
==============================================================================
--- poi/trunk/poi/src/main/java/org/apache/poi/ss/format/CellFormatPart.java (original)
+++ poi/trunk/poi/src/main/java/org/apache/poi/ss/format/CellFormatPart.java Wed Nov 24 09:55:33 2021
@@ -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})?\\])";
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org