phpintegerdoublegettype

why gettype(10.5 + 10.5); returns double? not integer


when I tried to

gettype(10.5 + 10.5);

it returns double or float but the summation of 10.5 + 10.5 = 21 which is actually an integer


Solution

  • gettype() is a function that lets you see the data type.

    You add a double (10.5), and another double (10.5), you get yet another double (21.0), which is what the function returns you.

    More details can be found here: https://www.php.net/manual/en/function.gettype.php