Search code examples
asp.netvb.netepplus

EPPlus is rounding up a large number


I am using EPPlus to generate an excel report in ASP.Net. I have the following code in use:

aCell.Value = CDec(aValue)

aCell is of type OfficeOpenXml.ExcelRange.

This works fine most of the time. However, when aValue is 201600000000515561, the cell in Excel is set with the value of 201600000000516000.

Stepping through the code and watching the value of aCell.Value shows that the correct value being set. But when the excel is opened, the value has been rounded up to the next 1000.

Does anybody have a solution or is this a bug in EPPlus?


Solution

  • Its not an Epplus thing, more of an Excel thing. Because of the way excel stores numbers you have up to 15 significant figures after which excel basically inserts 0's. If you count 201600000000515561 starting from the left you will see this. Have a look at this:

    https://en.wikipedia.org/wiki/Numeric_precision_in_Microsoft_Excel

    I think the most popular work around would be to store the numbers as text which of course leads to its own set of issues. Here is a good thread on it:

    http://answers.microsoft.com/en-us/office/forum/office_2007-excel/15-digit-number-limitation-non-text-workaround/a4974853-7c3c-4830-8562-2e88369d981b?auth=1