6

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)

Phill Pafford
  • 83,471
  • 91
  • 263
  • 383

3 Answers3

10

They're the same thing http://php.net/manual/en/language.types.float.php

Matteo Pagliazzi
  • 5,140
  • 12
  • 49
  • 83
7

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") ...

Bee
  • 2,472
  • 20
  • 26
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));

?>
sameerNAT
  • 95
  • 1
  • 3
  • 1
    Copy and Paste this code block above into your PHP test file and see the results appear in your Javascript _**Console**_ window. – sameerNAT Jun 02 '16 at 15:39