Php 当值小于1时,浮点返回0
我有个问题。我使用echo函数打印一个值,但不打印结果,而是使用var_dump返回值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) 功
//$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'])代码>真实(复制和粘贴)