Q:

Attempting to write float to CSV, but it becomes an integer

I'm using python 3 to create a csv file with different types of data, one of them being a float. Strings and integers show up correctly on the generated file, but the float becomes a large integer instead of retaining the decimals. For exmaple, 64.5232323 becomes 645.232.323. 
The data is organized in an array and I'm using python's csv module. Here's the code for writing to file:
    index_file_exists = os.path.isfile(full_dir+index_filename)
    with open(full_dir+index_filename, 'a+') as f:
        csv_file = csv.writer(f, delimiter=";")
        csv_file.writerow(index_line)

index_line is the array containing all the data for that row. I have tried converting the float to a formatted string, as in:
index_line[12] = "%.5f" % index_line[12]
But the value is still displayed as an integer when opened with Excel. If opened with a text editor like notepad, the float is shown correctly. I don't use excel or csv files regularly, so I'm at a loss here. Any suggestions?

A:

Check the locale / region settings of Excel.
If your region specifies "." as "thousands separator", then your formatted number will be treated as integer.
And use the str.format() function, which has a locale-sensitive formatter:
# Python < 3.6
index_line[12] = "{:.5n}".format(index_line[12])

# Python >= 3.6
index_line[12] = f"{index_line[12]:.5n}"

