我一直在做一个华氏温度摄氏(反之亦然)计算器。它所有的工作都很好,但是当我试图计算32华氏度到摄氏温度时,它应该是0,但是什么都不显示。我不明白为什么它不会回显0值。为什么PHP不打印0值?
下面是一些代码:
<?php
// Celsius and Fahrenheit Converter
// Programmed by Clyde Cammarata
$error = '<font color="red">Error.</font>';
function tempconvert($temptype, $givenvalue){
if ($temptype == 'fahrenheit') {
$celsius = 5/9*($givenvalue-32);
echo $celsius;
}
elseif ($temptype == 'celsius') {
$fahrenheit = $givenvalue*9/5+32;
echo $fahrenheit;
}
else {
die($error);
exit();
}
}
tempconvert('fahrenheit', '50');
?>
它为我打印0。 'larry $ php temp.php 0' 。但是你不需要引用临时值。 – 2014-12-06 02:54:35
你会得到什么错误?如果将其更改为(5/9)*($ givenvalue -32),会发生什么问题如果操作顺序给您的除零误差。 – Doon 2014-12-06 02:56:50
你有没有试过'echo(string)$ celsius;'? – Sablefoste 2014-12-06 02:57:58