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

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....

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.

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

Related

Round decimal points in excel

Hey guys I have a situation where I need to format a column to display APR(%) values in a certain way. Basically the values should be formatted like below:
Raw input Formatted value
========= ===============
0 0
0.0 0
4.4566 4.5
5.00 5
6 6
6.4 6.4
I tried creating this formula below but for some reason it doesn't round the number to 2 decimal places.
=INT(ROUND(A1,1)*100)/100
What am I doing wrong? Or is there a better way to handle this?
UPDATE: So I am applying the function to the same cell as the number is in. For instance the A1 cell contains 4.566 value and I applied the function to that same cell and this doesn't seem to be working for Excel. Any other ways to do this?
P.S: Im using the MS Excel for Mac
Two steps
Format the cells to Number with one decimal place
Conditionally format the cells to a Number Format of General if the value is an integer
EDIT: Since you cannot conditionally format the number format in Excel for MAC, there are several workarounds.
If you do not mind changing the actual value, add a column which you will use to display the result. Format the Column as "General", and use this formula (assuming your "real data" is in column A:
=IF(A1<>INT(A1),ROUND(A1,1),A1)
Other options that may work would include using an event-triggered macro (if that can be done in Excel for Mac); and possibly you can create the worksheet in Excel for Windows and the conditional format might be recognized in Excel for Mac, even if you can't create it there.
As explained in the documentation here,
Suppose that cell A1 contains 823.7825.
...
=ROUND(A1,2) ... equals 823.78
You should be able to therefore apply this to your entire column to get the precision that you are after.
Rather than using =INT(<another_cell_value>*100)/100 to derive the format you want, simply specify a custom format with the following:
#,###.##
This way, you only get the number of decimal places that you specified in the ROUND function.

number formatting is changed erroneously to time/date

I have a spreadsheet with numerous formats, mostly time and whole number. Data validation is present to assure proper formats. certain fields can be selected and VBA programmatically inserts the system time to the selected cell. This works perfectly and is very helpful when using this sheet. The problem occurs if a cell that should have a whole number (and definitely not a time) is accidently selected, then the "enter system time" code is run. This changes the format of that cell to time/date. said in another way, A1 is formatted for Number, 0 decimal places. A1 is selected and the "Enter system time" macro is run. The macro is not affected by the data validation rule that would otherwise prohibit anything but a whole number between 1 and 999. Now that the formatting is changed by VBA (somehow), when you enter, say, 5 into that (formerly) number-formatted cell, displayed is 1/5/1900 0:00. Because this is a compiled workbook, the change is permanent; the cell format cannot be changed back.
so, my question is: Is there a workaround? Is there a way to prevent this sort of format change? is there a way to unlock the cell if the format is wrong? Is there any sort of suggested method to avoid this?
You can check if the format is a number with 0 decimal places using the NumberFormat property of the Range object like:
If Range("A1").NumberFormat = "0" Then
'Some Code
End If
Check https://msdn.microsoft.com/pt-br/library/office/ff196401.aspx for more information on formats
Finally got this. The correct number formatting command is:
If Selection.NumberFormat = "[$-409]h:mm AM/PM;#" Then...

Which is the correct way of pasting?

I want to ask a very simple and maybe for some it may sound silly.
One person told that while copying and pasting in Excel you should use Paste Special and paste formats first and then values, then it keeps any leading zeros or else they will be removed. But someone else told other way round i.e. first values and then formats. I didn't notice any change also if I pasted as it is after copying.
So please tell me if these people are true and if yes which exactly is the correct order?
Oh, the joy of Excel conversions. You have to be cautious with your different circumstances.
Time to have some fun. Try this:
In cell A1 format the data as Text and enter the value 010.
In cell A2 leave the format as general and enter as 010.
Now go to the immediate window in VBIDE and execute the following:
? Typename(Range("A1").Value)
? Typename(Range("A2").Value)
A1 is a string, and A2 is a double.
If you change the format of A1 now to General then again type:
? Typename(Range("A1").Value)
It is still string - AND it still has the leading 0 at the front!
HOWEVER: now execute the following:
range("A1").Value = range("A1").Value
Although this looks like a pointless command - its effectively updates the cell by using VBA. Excel will now do the conversion to a double!!
? Typename(Range("A1").Value)
This is now a double.
So altering the format after the data can result in different data because Excel is doing a clever conversion. But this is dependant on the cell being updated. Just changing the cell format might change that value, but not necessarily - and later it could change if a user presses F2 and enter on the cell. Lovely - thank you excel for being intelligent.
Don't even get me started with other conversions.
So, I suggest that in the majority of cases, you should actually format first and data after.
Happy pasting! :)
Cell value and cell format are two distinct properties of a cell in Excel.
For displaying values, excel applies the format of the cell to its value. So if your cell holds a number and the format specifies that the number should have leading zeros, the number will be displayed with a leading zero. This does not change the underlying value!
The format affects only the display.
As an example:
Let's say your cell holds the value 5.5 as numerical value. Applying the format 0.00 will display that value as 5.50. Applying the format 0.00 min will display the same value as 5.50 min. But the value itself is still unchanged 5.5 - this way, you can e.g. be very specific about how you want to display a number, but still use its plain value for calculations. Same principles apply to every other formatting rule and data type of course.
So no matter which way round you paste - as long as the cells end up with the correct combination of value and format, you will end up with the correct result.

Using EPPlus, how do I return a cell value as it has been formatted by Excel?

I use EPPlus to load an Excel file that has numeric cells having this special format:
00"."00"."00"."000"."0
Hence, a cell value of 123456789 is displayed on Excel as 01.23.45.678.9
It's a sort of a material coding standard. Now, I would like to use EPPlus to return the formatted value in a string. I am not really interested in the numeric value. Also, I don't want to do the formatting manually in my code because the number format may sometimes vary. How would I do this?
Thank you :)
This looks like an issue in EPPlus. (update: I filed an issue.)
If you run your example with EPPlus under a debugger, you'll see that EPPlus is producing the string value from ExcelRangeBase.cs:965 using the expression d.ToString(format, nf.Culture) where d is the converted double value of your cell's text, format is "00.00.00.000.0", and nf is an EPPlus ExcelFormatTranslator (but the latter is not important to this particular issue).
The issue is that an un-literalized . in a custom numeric format string is taken to be a decimal point. So the value of format at this point in the EPPlus code should be "00'.'00'.'00'.'000'.'0".
I'm not yet sure what would be the best fix for this, but it looks to require a change somewhere in ExcelNumberFormatXml.ExcelFormatTranslator.ToNetFormat.
In the meantime, you don't have to do the formatting manually in your own code. Before calling the Text property, you can set the number format to what it should be, e.g.:
range.Style.Numberformat.Format = "00'.'00'.'00'.'000'.'0";
Now range.Text should give you the string you were expecting.

Get Excel to display full values

I have an Excel spreadsheet with a range of values which are numbers that go to up 20 decimal places, unpivoted from another sheet using the trick from here.
The trouble is the cells are only displaying 10 digits so, for example, even though the value is 5.46827166811115 it is showing as 5.468271668.
I've tried setting the format to text but it still wants to treat it as a number, the number of decimal places varies so I can't use a fixed #.### format. The only way I can get it to show is to format the cells as text and to just select and then click in the entry box for each and every cell!
It then shows a warning that the number in the cell is formatted as text or preceded by an apostrophe but at least it's showing the full value.
I did find a VBA script that just did something stupidly simple like cell.Value = cell.Value for the selection which seemed to work but I can't find it anymore and I can't reproduce that now.
Surely there's an easier way to do this? It wouldn't matter so much but when I import this data through SSIS into a VARCHAR(MAX) it's getting the truncated values!
Pre-pend a single apostrophe ' to the data. In many cases, this is more effective than setting the cell format to text.
You could format the cell as text and the do an .AutoFit so the cell expands to show all the cell content, like this:
Columns("A:A").EntireColumn.AutoFit
that will expand the A:A cell so all its content is visible.
try formatting with #.000 instead of #.###, but if your problem is that Excel is dropping precision on you, you could try multiplying the value by 10^20, then dividing by 10^20 on the SQL side.
found more info:
here
looks like Excel is limited to 15 digits of precision, multiplying by 10^20 doesn't increase the precision, so you can treat it like text or split the remaining digits into another column and combine them back with SSIS or SQL.
Have you added the IMEX=1 to your connection string? That keeps SSIS from trying to figure out the data from the first few rows.
Also, what about using a decimal datatype instead of varchar(max)

Resources