I have an implementation with gembox library and I'm reading numeric values from an excel file.
The are values for example that gembox reads like 101.41179656982422 but if I open the excel in cell value is 101.411796569824
I have an implementation with gembox library and I'm reading numeric values from an excel file.
The are values for example that gembox reads like 101.41179656982422 but if I open the excel in cell value is 101.411796569824
I believe we figured out what the problem was, let's consider the following sample code:
var ef = new ExcelFile();
var ws = ef.Worksheets.Add("Sheet1");
double number = 0.12345678912345678;
ws.Cells["A1"].Value = number;
ef.Save("Sample.xlsx");
The number
variable has 17 decimal digits of precision. In .NET Framework a System.Double value has up to 15 decimal digits of precision, although a maximum of 17 digits is maintained internally, see here.
But in MS Excel the number precision maximum limit is 15 digits, see here.
So in short, in the above sample the resulting output file will have all 17 decimal digits written in it, but when you open this file with MS Excel it will round that value to 15 decimal digits.
To avoid this difference you'll need to make sure that your double values have always a maximum of 15 decimal digits, for example:
double number = 0.12345678912345678;
double roundedNumber = Convert.ToDouble(number.ToString());
ws.Cells["A1"].Value = roundedNumber;