tags:

views:

95

answers:

1

Hi , i am reading the excel sheet from c# by using interop services. My sheet have one of cell value as 0.00. but run time when i checking the value of that cell in c# code I am getting "1.845E-07" this value. When i check in excel sheet, on that cell right clicked , say format cell I got "1.845E-07" value in sample section. How to get exact value? Please help me. code is huge, so i can't provide it here . that line is:

if (Convert.ToString(((Excel.Range)worksheet.Cells[iRowindex, colIndex_q10]).Value2) != string.Empty)
                    {
                        drRow[dtSourceEXLData.Columns[constants.Floor]] = ((Excel.Range)worksheet.Cells[iRowindex, colIndex_q10]).Value2.ToString();
                    }

Same problem with Date cells "39448". what does this means??please help....

+2  A: 

1.84E-07 is the exact value, represented using scientific notation, also known as exponential notation.

1.845E-07 is the same as 0.0000001845. Excel will display a number very close to 0 as 0, unless you modify the formatting of the cell to display more decimals.

C# however will get the actual value from the cell. The ToString method use the e-notation when converting small numbers to a string.

You can specify a format string if you don't want to use the e-notation.

Kjetil Watnedal
but how to specify it string?? steps please.
Lalit
well done ... now object testval = ((Excel.Range)worksheet.Cells[iRowindex, colIndex_q10]).Value2; double dbl1 = Convert.ToDouble(testval); //if (Convert.ToString(((Excel.Range)worksheet.Cells[iRowindex, colIndex_q10]).Value2) != string.Empty) if (testval != null //((Excel.Range)worksheet.Cells[iRowindex, colIndex_q10]).Value2.ToString(); }
Lalit