Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

saving csv from excel loses decimal point precision

If I create a simple .csv file containing something like this:

01/22/2013,3.14159265358979323846264338

and proceed to open it up in excel, the cell will show a rounded number i.e. 3.141592654 and the formula bar will show the whole value. However if I make some changes and save the csv file, or just save the original file as a different csv file, the file will only contain the rounded number 3.141592654, causing me to lose some decimal point precision.

I am writing these files out via a vba macro. I have tried :

ActiveWindow.DisplayFormulas=True

before the save command, and it works except it changes my date into a numeric format and I have not figured out a way to apply this format to only a range of cells. Is there some simple way to keep my numeric precision?

like image 248
LostLin Avatar asked Jan 22 '13 15:01

LostLin


People also ask

How do I save a CSV file without losing decimals?

To preserve all the digits in text-formatted numbers, you have to import the downloaded CSV file as raw data into a new Excel spreadsheet, set the column datatypes as needed, and then save the new file as an Excel workbook. Excel (XLSX) files will preserve these formats, CSV files won't.

How do I keep decimal places in CSV?

CSV file, you cannot keep decimal digits directly. However, you can change the number of decimal places that are displayed for this value. For example, when the data is like 123457.78 in the underlying data, you can change decimal places as 0 to display is like 123457 to export as a . Csv.

Why does my decimal point disappear in Excel?

If, for example, you enter a number in a cell with General formatting (the default for all cells on a new worksheet), then Excel automatically displays fewer decimal places so that the number fits within the width of an empty cell.


1 Answers

If you know which cells are going to be affected, try something like

Range("MYNUMBERS").NumberFormat = "#0.000000000000000"

?

like image 88
Vinny Roe Avatar answered Oct 12 '22 08:10

Vinny Roe