-
Notifications
You must be signed in to change notification settings - Fork 294
Precision as Displayed
Jan Källman edited this page Aug 20, 2024
·
3 revisions
From EPPlus version 7.3, Precision as Displayed is supported by setting the property ExcelWorkbook.FullPrecision
to false
.
When using Precision as Displayed, EPPlus rounds all numeric values according to the number format of the cell.
This affects both cell values and formula calculation results.
using (var p = new ExcelPackage())
{
var ws = p.Workbook.Worksheets.Add("Sheet1");
ws.Cells["A1"].Value = 123.456789;
ws.Cells["A2"].Value = 987.654321;
ws.Cells["A3"].Formula = "SUM(A1:A2)";
ws.Cells["A1:A3"].Style.Numberformat.Format = "#,##0.00";
p.Workbook.FullPrecision = false; //This will round the values in A1 and A2 according to the number format "#,##0.00".
//Any changes to cells will also be rounded depending on the number format.
ws.Calculate(); //Calculation results will also be rounded in the sane way.
//Now the values in A1:A3 will be:
Assert.AreEqual(123.46, ws.Cells["A1"].Value);
Assert.AreEqual(987.65, ws.Cells["A2"].Value);
Assert.AreEqual(1111.11D, ws.Cells["A3"].Value);
}
Using Precision as Displayed will obviously lower the precision, but can be helpful if you want to mimic the results shown in the spreadsheet application or to reduce floating point issues.
EPPlus Software AB - https://epplussoftware.com
- What is new in EPPlus 5+
- Breaking Changes in EPPlus 5
- Breaking Changes in EPPlus 6
- Breaking Changes in EPPlus 7
- Breaking Changes in EPPlus 8
- Addressing a worksheet
- Dimension/Used range
- Copying ranges/sheets
- Insert/Delete
- Filling ranges
- Sorting ranges
- Taking and skipping columns/rows
- Data validation
- Comments
- Freeze and Split Panes
- Header and Footer
- Hyperlinks
- Autofit columns
- Grouping and Ungrouping Rows and Columns
- Formatting and styling
- The ExcelRange.Text property
- Conditional formatting
- Using Themes
- Working with custom named table- or slicer- styles