what is this value means 1.845E-07 in excel?
Asked Answered
P

2

7

I am reading the excel sheet from C# by using interop services. My sheet has one of cell value as 0.00. but run time when I am 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. The 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....

Pharmacy answered 5/5, 2010 at 11:45 Comment(0)
A
17

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.

Amil answered 5/5, 2010 at 12:5 Comment(2)
but how to specify it string?? steps please.Pharmacy
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 && testval != string.Empty) { drRow[dtSourceEXLData.Columns[constants.Floor]] = dbl1.ToString("F");//((Excel.Range)worksheet.Cells[iRowindex, colIndex_q10]).Value2.ToString(); }Pharmacy
S
1

Highlight the cells, format cells, select Custom then select zero.

Scrawly answered 2/7, 2014 at 16:30 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.