Solved

20 digit numbers imported via CSV - converted to scientific notation in Excel -

Posted on 2014-01-31
6
1,306 Views
Last Modified: 2014-01-31
hi Folks
Hope you are well.
Got a scenario :-)
Person has very large numbers to download from CSV file (18 plus digits).
When they get to Excel, they are converted to scientific notation...then when the user wants to convert them back to CSV and upload to original programme (as values), they run into problems. So my question is this..
Is there a way to retain the numbers' multiple digits (I know you could do that via Text Wizard and bring in as text) to be suitable for uploading back to original programme.

Thank you as always.
0
Comment
Question by:agwalsh
  • 3
  • 2
6 Comments
 
LVL 27

Assisted Solution

by:MacroShadow
MacroShadow earned 166 total points
ID: 39823401
Excel will only retain 15 significant digits. The only workaround is to change the extension to .txt and open the file using the text import wizard, specifying those fields as Text. Or do the same thing using VBA.

Here is the VBA option by taylourmackay:
Public Sub ReadCSV(strFile As String)
    Application.ScreenUpdating = False
    Dim oFSO As New FileSystemObject, oFS As TextStream
    Dim strLine As String, aLine As Variant, nRow As Long, nColumn As Long
    
    nRow = 1
    nColumn = 1
   
    Set oFS = oFSO.OpenTextFile(strFile)
    Do Until oFS.AtEndOfStream
        strLine = oFS.ReadLine
        aLine = Split(strLine, ",")
        With Range(Cells(nRow, nColumn), Cells(nRow, nColumn + UBound(aLine)))
            .NumberFormat = "@"
            .Value = aLine
        End With
        nRow = nRow + 1
    Loop
    oFS.Close
    Application.ScreenUpdating = True
End Sub

Public Sub SaveCSV(ByVal strFile As String)
    Dim oFSO As New FileSystemObject, oFS As TextStream
    Set oFS = oFSO.OpenTextFile(strFile, ForWriting, True)
   
    Dim i As Long, lastRow As Long, lastColumn As Long, strLine As String, aTemp As Variant
    lastRow = ActiveSheet.UsedRange.Rows.Count + ActiveSheet.UsedRange.Row - 1
    lastColumn = ActiveSheet.UsedRange.Columns.Count + ActiveSheet.UsedRange.Column - 1
    For i = 1 To lastRow
        aTemp = Application.WorksheetFunction.Transpose(Application.WorksheetFunction.Transpose(Range(Cells(i, 1), Cells(i, lastColumn))))
        strLine = Join(aTemp, ",")
        oFS.WriteLine strLine
    Next i
    oFS.Close
End Sub

Open in new window

0
 
LVL 3

Assisted Solution

by:ola_erik
ola_erik earned 334 total points
ID: 39823404
Nah u have to use text:

As with other spreadsheets, Microsoft Excel works only to limited accuracy because it retains only a certain number of figures to describe numbers (it has limited precision). Excel nominally works with 8-byte numbers by default, a modified 1985 version of the IEEE 754 specification[1] (Besides numbers, Excel uses a few other data types.[2]) Although Excel can display 30 decimal points, its precision for a specified number is confined to 15 significant figures, and calculations may have an accuracy that is even less due to three issues: round off,[3] truncation, and binary storage.

http://en.wikipedia.org/wiki/Numeric_precision_in_Microsoft_Excel
0
 

Author Comment

by:agwalsh
ID: 39823446
These figures would be 18 digits (not 18 decimal places..) ...does that make a difference (I don't think so based on what you have said.. :-)
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 3

Accepted Solution

by:
ola_erik earned 334 total points
ID: 39823466
disregard the decimal points.
excel keeps track of 15 digits, u have 18
u need to use text
0
 

Author Comment

by:agwalsh
ID: 39823714
Not what I hoped to hear but at least I have an answer :-)
0
 

Author Closing Comment

by:agwalsh
ID: 39823716
Thank you :-)
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Access 2013 won't install with Office 2016 (Home and Business) 8 32
Excel case statements 3 25
Mac Excel column treating text as date 2 32
excel help 4 20
In this article we discuss how to recover the missing Outlook 2011 for Mac data like Emails and Contacts manually.
This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
Graphs within dashboards are meant to be dynamic, representing data from a period of time that will change each time the dashboard is updated with new data. Rather than update each graph to point to a different set within a static set of data, t…
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.

862 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now