Skip to content

Commit

Permalink
another dataformatter test
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1918817 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
pjfanning committed Jul 2, 2024
1 parent 05c7932 commit 04c9d0a
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ Licensed to the Apache Software Foundation (ASF) under one or more
import org.apache.poi.ss.usermodel.BaseTestDataFormat;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.DataFormat;
import org.apache.poi.ss.usermodel.DataFormatter;
import org.apache.poi.ss.usermodel.FormulaEvaluator;
import org.apache.poi.ss.usermodel.Workbook;
Expand Down Expand Up @@ -158,18 +159,5 @@ public void testFormatCellValue() throws IOException {
*/
}
}

@Test
public void testFormatCellValueDecimal() throws IOException {
DataFormatter df = new DataFormatter();

try (Workbook wb = new XSSFWorkbook()) {
Cell cell = wb.createSheet("test").createRow(0).createCell(0);
assertEquals("", df.formatCellValue(cell));

cell.setCellValue(1.005);
assertEquals("1.005", df.formatCellValue(cell));
}
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,11 @@ Licensed to the Apache Software Foundation (ASF) under one or more
import org.apache.poi.ss.usermodel.BaseTestDataFormat;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.DataFormat;
import org.apache.poi.ss.usermodel.DataFormatter;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.junit.jupiter.api.Test;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -273,4 +273,24 @@ public final void test55265() throws IOException {
assertEquals("12'345'678", formatter.formatCellValue(lge));
}
}

@Test
public void testFormatCellValueDecimal() throws IOException {
DataFormatter df = new DataFormatter();

try (Workbook wb = _testDataProvider.createWorkbook()) {
Cell cell = wb.createSheet("test").createRow(0).createCell(0);
assertEquals("", df.formatCellValue(cell));

cell.setCellValue(1.005);
assertEquals("1.005", df.formatCellValue(cell));

DataFormat format = wb.createDataFormat();
CellStyle cellStyle = wb.createCellStyle();
cellStyle.setDataFormat(format.getFormat("0.00"));
cell.setCellStyle(cellStyle);
assertEquals("1.01", df.formatCellValue(cell));
}
}

}

0 comments on commit 04c9d0a

Please sign in to comment.