Solved

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

Posted on 2014-01-31
6
1,324 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
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 
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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
IT Desktop Support 11 68
Count Unique Values in column if cell matches 3 24
how to add loop into this VBA 3 28
vba autofilter in row 4 6 8
Using Word 2013, I was experiencing some incredible lag when typing.  Here's what worked for me....
Do you use a spreadsheet like Microsoft's Excel?  Have you ever wanted to link out to a non excel file on your computer or network drive?  This is the way I found to do it!
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

776 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