为什么 gettype() 说它是 double 而 var_dump() 说它是 float?

发布于 2024-12-13 17:36:50 字数 294 浏览 6 评论 0原文

为什么 gettype() 说它是 double 而 var_dump() 说它是 float?

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

回复:

数字:1.23456789012E+18 是一个双精度
浮动(1.23456789012E+18)

Why does the gettype() say it's a double but var_dump() says float?

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

Response:

Number: 1.23456789012E+18 is a double
float(1.23456789012E+18)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

假情假意假温柔 2024-12-20 17:36:50

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

返回字符串的可能值为:

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

Directly from PHP.net (gettype()):

Possibles values for the returned string are:

...
"double" (for historical reasons "double" is returned in case of a float, and not simply "float") ...

我为君王 2024-12-20 17:36:50
<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));

?>
<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));

?>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文