为什么gettype()说它是double,但var_dump()表示float?

时间:2011-11-04 15:41:38

标签: php gettype var-dump

为什么gettype()说它是double,但var_dump()表示float?

$number = 1234567890123456789;
echo "Number: {$number} is a ". gettype($number) . "\n";
var_dump($number);

响应:

  

编号:1.23456789012E + 18是双双   浮子(1.23456789012E + 18)

3 个答案:

答案 0 :(得分:7)

答案 1 :(得分:4)

直接来自PHP.net(gettype()):

  

返回字符串的可能值为:

     

...   “double”(由于历史原因,在浮动的情况下返回“double”,而不是简单地“浮动”) ......

答案 2 :(得分:0)

<br>
<?php 
        /*begins with a function that runs a Console msg for PHP */
function console_sn($txt){
$temp = "";
$temp .= "<script>";
$temp .= "console.info('frm_PHP: '+'";
$temp .= $txt;
$temp .= "');";
$temp .= "</script>";
echo $temp;
}
echo("<br><hr><br>");
//end of PHP console function

//Main primary code for this Example begins below

//run these examples below in your test PHP file and see the results in your JS console window

//e.g.#1
$code1 = "1212";
console_sn(gettype(floatval($code1)));

//e.g.#2
$code2 = "1212sn";
console_sn(gettype(floatval($code2)));

//e.g.#3
$code3 = "1212";
console_sn(gettype((trim($code3))*1));

//e.g.#4
$code4 = "1212sn";
console_sn(gettype((trim($code4))*1));

?>