phpphp-7.2export-csv

In exported csv value with number_format not showing with separated comma


In my project, I am using the below code to format the number

$row[$k] = number_format($number, 2, '.', ',');

When I export the xlsx file it working properly and I am getting data like

2,607,697.14

But the issue is in csv. when I export the csv file I am getting data like

2607697.14

And If I am using below code

$row[$k] = '"' . number_format($number, 2, '.', ',') . '"';

For both csv and xlsx, I am getting

"2,607,697.14"

I don't understand why I am not getting the value with comma in csv? And how I can get the value as I want? Data display in csv file:

Total Sales Total Amount Total Commission

234 2607697.14 148693.56

Data display in xlsx:

Total Sales Total Amount Total Commission

234 2,607,697.14 148,693.56


Solution

  • The difference between CSV and XLS file formats is that CSV format is a plain text format in which values are separated by commas, while XLS file format is an Excel Sheets binary file format which holds information about all the worksheets in a file. So in CSV file you are getting numeric value as a plain text string but in XLS file same value shown as a formatted number.

    In XLS, You can export image, links, symbols, charts but not in CSV.