Forum Discussion
Importing a .csv file to Excel. Not all decimals are present in Excel
Please provide some examples.
On input, Excel interprets only the first 15 significant digits (after any leading zeros). Any digits to the right are replaced with zeros.
Also, Excel formats only up to the first 15 significant digits (rounded). But Excel will format only up to 30 decimal places.
So if your values are less than 1E-16, you need to format as Scientific with 14 decimal places to see the max precision.
- jhbunceApr 03, 2023Copper Contributor
JoeUser2004 - here is an example. In the .csv file, when viewing it via Notepad++, I have this value -= 14759359.090908095. When I open this file in Excel, the value is 14759359.0909081. If this is a field size limitation, is there any plans by MS to expand the size?
- JoeUser2004Apr 03, 2023Bronze Contributor
jhbunce wrote: ``this value -= 14759359.090908095. When I open this file in Excel, the value is 14759359.0909081``
I'm surprised and incredulous.
When I enter that number in Excel, I get 14759359.0909080, which is the truncated first 15 significant digits of the string 14759359.090908095.
I wonder: are you "opening" the CSV file by reading the data in VBA?
VBA does not truncate the data entry. So, when we type 14759359.090908095, we get that exact binary value.
Caveat: But since VBA displays only the first 15 significant digits (rounded), like Excel, that value will change to the binary value of 14759359.0909081 if the line is edited.
Aside.... The binary value of VALUE("14759359.0909080") is different from the binary value of VALUE("14759359.0909081"). And both are different from the binary value of vbvalue("14759359.090908095"). See the implementation of vbvalue below.
-----
Re: ``is there any plans by MS to expand the size?``
I would have no idea, since I do not work for MSFT. I would say that it is unlikely, since a change would present significant backward compatibility issues. However, MSFT could provide an option.
Although Excel does have an arbitrary limit on data entry, the primary limitation is the internal binary representation, which is 64-bit binary floating-point.
Contrary to most online documentation, the internal representation is not limited to 15 significant digits.
But it can be approximated by up to 17 significant digits with no loss of precision when converting between decimal and binary.
I suspect that is the data that you see. For example, 14759359.090908095 is the 17 significant digit approximation of the value that we might write as 14759359.0909080 + 9.50E-08 or 14759359.0909081 - 5.59E-09.
-----
Function vbValue(s As String) As Double
vbValue = CDbl(s)
End Function- jhbunceApr 03, 2023Copper ContributorAll I am doing is, via excel, opening the .csv file. I'm not sure to what you are referring when you say "are you "opening" the CSV file by reading the data in VBA?".