Почему gettype () говорит, что это double, а var_dump () говорит, что float? - PullRequest
3 голосов
/ 04 ноября 2011

Почему gettype () говорит, что это двойное число, а var_dump () говорит, что оно float?

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

Ответ:

Число: 1.23456789012E + 18 - двойное числоfloat (1.23456789012E + 18)

Ответы [ 3 ]

7 голосов
/ 04 ноября 2011
4 голосов
/ 04 ноября 2011

Непосредственно с PHP.net ( gettype () ):

Возможные значения для возвращаемой строки:

... «double» (по историческим причинам «double» возвращается в случае с плавающей точкой, а не просто с «float») ...

0 голосов
/ 02 июня 2016
<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));

?>
...