Re: CSV output.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This is a bug/feature of Excel.

If the field it marked as type of General, the default field type, Excel will
truncate the zeros to the right of the decimal.

price,55.55
price,55.50
price,55.00

copy these values

create a new text file, call it test.csv

paste the above values into it.

now, open it with excel.

you will see the same output that you are seeing with your PHP script.

This it not a PHP problem!  This is an Excel feature/bug/problem!!!

Tom Shaw wrote:
> This statement _is_ correct. I see values such as 234.55, but not 234.00 in
> the CSV file and when I dump the data.
> 55.00 will equal 55 when it should equal 55.00. 234.00 shows up as 234. The
> data is fine it just simple does not show up
> correctly in the CSV file.
> 
> $out
> .="".$name.",".$description.",".$size.",".$stock.",".$price.",".$total_cost.
> "";
> $out .= "\n";
> 
> }
> 		
> dump($out); This prints the correct data.
> exit();
> 				
> header("Content-type: application/vnd.ms-excel");
> header("Content-Disposition: attachment; filename=inventory_report.csv");
> 
> print $out; This prints wrong.
> 
> -----Original Message-----
> From: Eric Gorr [mailto:mailist@xxxxxxxxxxxx] 
> Sent: Monday, September 08, 2008 4:21 PM
> To: PHP General
> Subject: Re:  CSV output.
> 
> 
> On Sep 8, 2008, at 5:06 PM, Tom Shaw wrote:
> 
>> Actually that won't work I tried it. For some reason the .00 shows  
>> up when I
>> try to manually add a .00. I know weird.
> 
> Did you mean to say that it .00 _doesn't_ show up when you try to  
> manually add a .00?
> 
>> The value is in the array or string
>> before outputting printing to CSV. Number format does not work either.
> 
> 
> And just to clarify...in your .csv file, you do see values such as  
> 234.55, but not 234.00.
> 
> I can promise you that if you fprintf( $fp, "234.00" ), you will see  
> 234.00 in your file.
> 
> So, the question becomes, what _exactly_ are you doing when you are  
> writing this stuff out.
> 
> 
> 


-- 
Jim Lucas

   "Some men are born to greatness, some achieve greatness,
       and some have greatness thrust upon them."

Twelfth Night, Act II, Scene V
    by William Shakespeare


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux