Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/284.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/sql-server-2005/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 当值小于1时,浮点返回0_Php - Fatal编程技术网

Php 当值小于1时,浮点返回0

Php 当值小于1时,浮点返回0,php,Php,我有个问题。我使用echo函数打印一个值,但不打印结果,而是使用var_dump返回值 //$issue['fields']['timeestimate'] value is 2700 echo $this->toHours($issue['fields']['timeestimate']); return nothing var_dump($this->toHours($issue['fields']['timeestimate'])); return float(0.75) 功

我有个问题。我使用echo函数打印一个值,但不打印结果,而是使用var_dump返回值

//$issue['fields']['timeestimate'] value is 2700
echo $this->toHours($issue['fields']['timeestimate']); return nothing
var_dump($this->toHours($issue['fields']['timeestimate'])); return float(0.75)
功能是

private function toHours($seconds){
        return $seconds/3600;
}

怎么了?如果值为1或更高,它将返回正确的值。

也许您可以在除法之前转换为数值:

private function toHours($seconds){
        $seconds = intval($seconds);
        return $seconds/3600;
}
并使用printf()显示格式化的浮点值,如:

printf('%f', $this->toHours($issue['fields']['timeestimate']));

错误出现在处理它的循环中,对不起…

试试看,我想这就是你要找的…很可能是精度问题。阅读红色的大方框不起作用。echo函数继续不返回任何内容。这里的代码没有问题,bug肯定在其他地方。编码?
timeestimate
中的空格或特殊字符。请显示所有
var_转储($issue['fields']['timeestimate'])
var_转储($seconds/3600)
var_转储($this->toHours($issue['fields']['timeestimate'])真实(复制和粘贴)