Solved

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

Posted on 2014-01-31
6
1,275 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 26

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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

A little background as to how I came to I design this code: Around 5 years ago I designed an add-in that formatted Excel files to a corporate standard, applying different cell colours and font type depending on whether the cells contained inputs,…
Recently Microsoft released a brand new function called CONCAT. It's supposed to replace its predecessor CONCATENATE. But how does it work? And what's new? In this article, we take a closer look at all of this - we even included an exercise file for…
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…
Learn how to make your own table of contents in Microsoft Word using paragraph styles and the automatic table of contents tool. We'll be using the paragraph styles in Word’s Home toolbar to help you create a table of contents. Type out your initial …

709 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

13 Experts available now in Live!

Get 1:1 Help Now