I have the following C# code:
static void Main(string[] args)
{
double a = 1.2d;
double b = 3.1d;
double c = 0.17241379310344829;
double d = 0.25d;
Console.WriteLine("{0:G17}", a * b * c * d);
string CONNECTION_STRING = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0}; Extended Properties=\"Excel 12.0 Xml;HDR=YES\";";
using(var conn = new OleDbConnection(string.Format(CONNECTION_STRING, @"C:\TEMP\anyExcelFile.xlsx")))
{
conn.Open();
using(var sqlCmd = conn.CreateCommand())
{
sqlCmd.CommandType = System.Data.CommandType.Text;
sqlCmd.CommandText = "INSERT INTO [Sheet1$A1:A] VALUES (1)";
sqlCmd.ExecuteNonQuery();
}
}
Console.WriteLine("{0:G17}", a * b * c * d);
}
When I run it, the Console.WriteLine gives me the following results:
0.16034482758620688
0.16034482758620691
You need to have a excel file on C:\TEMP\anyExcelFile.xlsx (with a sheet named Sheet1) to be able to run it.
If I comment the ExecuteNonQuery line, and run again, I get:
0.16034482758620688
0.16034482758620688
Why executing excel causes double operation to return different results?