php - format of number on downloading in csv format -
following code returns hours given seconds, working.
<?php $hrs = seconds_to_dezi(278280); echo $hrs; $filename = "test"; header("content-type: application/vnd-ms-excel"); header("content-disposition: attachment; filename=$filename.xls"); function seconds_to_dezi($s) { $n = false; if ($s < 0) { $n = true; $s = -$s; } $h = round($s / 3600,2); $h = number_format($h,2, ',', ' '); $h = str_replace(".",",",$h); if ($n == true) { return ("-" . $h); } else { return ($h); } } ?> actual output in excel:- 77,3
expected output is:- 77,30
i.e on downloading values in csv format, trailing 0 after decimal truncated. want have 0 in excel.
the function returning 77,30. thing excel doesn't show final 0, it's there. open file text editor.
Comments
Post a Comment