下面的代码返回给定秒的小时数,这是正常的。
<?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);
}
}
?>
excel实际输出:- 77,3
预期输出:- 77,30
。在下载CSV格式的值时,十进制后的末尾零将被截断。我想在excel中显示0
函数返回77,30。问题是,Excel没有显示最后的0,但它在那里。使用文本编辑器打开文件
不能显式设置CSV文件中的小数位数。如果需要显示77,30,可以使用="70,30"。它将在文件中正确显示,但它将是文本。所以你不能再用它作为一个数字在excel中