Difference between float and double in php?





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







105















I have this code



$vad = 1.1;

print gettype($vad);

var_dump($vad);


this will output:



double
float(1.1)


So it is double or float in php?










share|improve this question































    105















    I have this code



    $vad = 1.1;

    print gettype($vad);

    var_dump($vad);


    this will output:



    double
    float(1.1)


    So it is double or float in php?










    share|improve this question



























      105












      105








      105


      11






      I have this code



      $vad = 1.1;

      print gettype($vad);

      var_dump($vad);


      this will output:



      double
      float(1.1)


      So it is double or float in php?










      share|improve this question
















      I have this code



      $vad = 1.1;

      print gettype($vad);

      var_dump($vad);


      this will output:



      double
      float(1.1)


      So it is double or float in php?







      php






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Jul 19 '10 at 12:29









      Amarghosh

      49.2k1078113




      49.2k1078113










      asked Jul 19 '10 at 12:10









      CenturionCenturion

      2,43962245




      2,43962245
























          4 Answers
          4






          active

          oldest

          votes


















          138














          There is no difference in PHP. float, double or real are the same datatype.



          At the C level, everything is stored as a double.

          The real size is still platform-dependent.



          See the manual for more details:
          http://www.php.net/manual/en/language.types.float.php






          share|improve this answer


























          • sure about that? are there some memory use diffrent about it?

            – TheCrazyProfessor
            Jan 1 '17 at 12:11






          • 1





            I have function function some( float $num){}, when i use some(17.23) it throws fatal error some() must be an instance of float, double given,

            – NaveenDA
            Sep 2 '17 at 9:02






          • 1





            @NaveenDA What version of PHP? Prior to PHP 7.0, scalar type hints were not available and would be interpreted as class names instead. That looks like what is going on there.

            – Ken Wayne VanderLinde
            Nov 1 '17 at 18:50



















          18














          For PHP, they are the same. http://www.php.net/manual/en/language.types.float.php :




          Floating point numbers (also known as "floats", "doubles", or "real numbers") can be specified using any of the following syntaxes: [...]




          The confusing part is why gettype (which you shouldn't use, anyway) returns "double" instead of "float". The answer is http://de2.php.net/manual/en/function.gettype.php:




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







          share|improve this answer































            5














            As of PHP 7.0.6 on Windows, comparing this command without xdebug:



            $ php -r 'var_dump(28.4);'
            float(28.4)


            and with xdebug:



            $ php -r 'var_dump(28.4);'
            Command line code:1:
            double(28.4)


            Note that this only changes var_dump() output, but not the actual memory management.



            This may address some concerns why you see double instead of float shown in var_dump in some other machines.



            Also, with or without xdebug, gettype still returns string(6) "double".






            share|improve this answer


























            • Very interesting! Thanks for pointing this out.

              – L S
              Dec 6 '17 at 16:40



















            1














            In PHP 7.0.14



            function test(double $a) {
            var_dump($a);
            }
            test(2.2111);


            Returns "Fatal error: Uncaught TypeError: Argument 1 passed to test() must be an instance of double, float given".



            function test(float $a) {
            var_dump($a);
            }
            test(2.2111);


            Prints 2.2111 to the screen.






            share|improve this answer



















            • 1





              Only float is a valid type hint (see). When you type double instead, it is treated as an class name, and interpreter throws the exception, because it expects a variable with instance of the double class

              – AterLux
              Oct 18 '18 at 12:24












            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f3280892%2fdifference-between-float-and-double-in-php%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            4 Answers
            4






            active

            oldest

            votes








            4 Answers
            4






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            138














            There is no difference in PHP. float, double or real are the same datatype.



            At the C level, everything is stored as a double.

            The real size is still platform-dependent.



            See the manual for more details:
            http://www.php.net/manual/en/language.types.float.php






            share|improve this answer


























            • sure about that? are there some memory use diffrent about it?

              – TheCrazyProfessor
              Jan 1 '17 at 12:11






            • 1





              I have function function some( float $num){}, when i use some(17.23) it throws fatal error some() must be an instance of float, double given,

              – NaveenDA
              Sep 2 '17 at 9:02






            • 1





              @NaveenDA What version of PHP? Prior to PHP 7.0, scalar type hints were not available and would be interpreted as class names instead. That looks like what is going on there.

              – Ken Wayne VanderLinde
              Nov 1 '17 at 18:50
















            138














            There is no difference in PHP. float, double or real are the same datatype.



            At the C level, everything is stored as a double.

            The real size is still platform-dependent.



            See the manual for more details:
            http://www.php.net/manual/en/language.types.float.php






            share|improve this answer


























            • sure about that? are there some memory use diffrent about it?

              – TheCrazyProfessor
              Jan 1 '17 at 12:11






            • 1





              I have function function some( float $num){}, when i use some(17.23) it throws fatal error some() must be an instance of float, double given,

              – NaveenDA
              Sep 2 '17 at 9:02






            • 1





              @NaveenDA What version of PHP? Prior to PHP 7.0, scalar type hints were not available and would be interpreted as class names instead. That looks like what is going on there.

              – Ken Wayne VanderLinde
              Nov 1 '17 at 18:50














            138












            138








            138







            There is no difference in PHP. float, double or real are the same datatype.



            At the C level, everything is stored as a double.

            The real size is still platform-dependent.



            See the manual for more details:
            http://www.php.net/manual/en/language.types.float.php






            share|improve this answer















            There is no difference in PHP. float, double or real are the same datatype.



            At the C level, everything is stored as a double.

            The real size is still platform-dependent.



            See the manual for more details:
            http://www.php.net/manual/en/language.types.float.php







            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Dec 11 '14 at 16:27









            ratchet freak

            41k44494




            41k44494










            answered Jul 19 '10 at 12:14









            MacmadeMacmade

            42.6k1193115




            42.6k1193115













            • sure about that? are there some memory use diffrent about it?

              – TheCrazyProfessor
              Jan 1 '17 at 12:11






            • 1





              I have function function some( float $num){}, when i use some(17.23) it throws fatal error some() must be an instance of float, double given,

              – NaveenDA
              Sep 2 '17 at 9:02






            • 1





              @NaveenDA What version of PHP? Prior to PHP 7.0, scalar type hints were not available and would be interpreted as class names instead. That looks like what is going on there.

              – Ken Wayne VanderLinde
              Nov 1 '17 at 18:50



















            • sure about that? are there some memory use diffrent about it?

              – TheCrazyProfessor
              Jan 1 '17 at 12:11






            • 1





              I have function function some( float $num){}, when i use some(17.23) it throws fatal error some() must be an instance of float, double given,

              – NaveenDA
              Sep 2 '17 at 9:02






            • 1





              @NaveenDA What version of PHP? Prior to PHP 7.0, scalar type hints were not available and would be interpreted as class names instead. That looks like what is going on there.

              – Ken Wayne VanderLinde
              Nov 1 '17 at 18:50

















            sure about that? are there some memory use diffrent about it?

            – TheCrazyProfessor
            Jan 1 '17 at 12:11





            sure about that? are there some memory use diffrent about it?

            – TheCrazyProfessor
            Jan 1 '17 at 12:11




            1




            1





            I have function function some( float $num){}, when i use some(17.23) it throws fatal error some() must be an instance of float, double given,

            – NaveenDA
            Sep 2 '17 at 9:02





            I have function function some( float $num){}, when i use some(17.23) it throws fatal error some() must be an instance of float, double given,

            – NaveenDA
            Sep 2 '17 at 9:02




            1




            1





            @NaveenDA What version of PHP? Prior to PHP 7.0, scalar type hints were not available and would be interpreted as class names instead. That looks like what is going on there.

            – Ken Wayne VanderLinde
            Nov 1 '17 at 18:50





            @NaveenDA What version of PHP? Prior to PHP 7.0, scalar type hints were not available and would be interpreted as class names instead. That looks like what is going on there.

            – Ken Wayne VanderLinde
            Nov 1 '17 at 18:50













            18














            For PHP, they are the same. http://www.php.net/manual/en/language.types.float.php :




            Floating point numbers (also known as "floats", "doubles", or "real numbers") can be specified using any of the following syntaxes: [...]




            The confusing part is why gettype (which you shouldn't use, anyway) returns "double" instead of "float". The answer is http://de2.php.net/manual/en/function.gettype.php:




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







            share|improve this answer




























              18














              For PHP, they are the same. http://www.php.net/manual/en/language.types.float.php :




              Floating point numbers (also known as "floats", "doubles", or "real numbers") can be specified using any of the following syntaxes: [...]




              The confusing part is why gettype (which you shouldn't use, anyway) returns "double" instead of "float". The answer is http://de2.php.net/manual/en/function.gettype.php:




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







              share|improve this answer


























                18












                18








                18







                For PHP, they are the same. http://www.php.net/manual/en/language.types.float.php :




                Floating point numbers (also known as "floats", "doubles", or "real numbers") can be specified using any of the following syntaxes: [...]




                The confusing part is why gettype (which you shouldn't use, anyway) returns "double" instead of "float". The answer is http://de2.php.net/manual/en/function.gettype.php:




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







                share|improve this answer













                For PHP, they are the same. http://www.php.net/manual/en/language.types.float.php :




                Floating point numbers (also known as "floats", "doubles", or "real numbers") can be specified using any of the following syntaxes: [...]




                The confusing part is why gettype (which you shouldn't use, anyway) returns "double" instead of "float". The answer is http://de2.php.net/manual/en/function.gettype.php:




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








                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Jul 19 '10 at 12:19









                Victor NicolletVictor Nicollet

                21.7k24587




                21.7k24587























                    5














                    As of PHP 7.0.6 on Windows, comparing this command without xdebug:



                    $ php -r 'var_dump(28.4);'
                    float(28.4)


                    and with xdebug:



                    $ php -r 'var_dump(28.4);'
                    Command line code:1:
                    double(28.4)


                    Note that this only changes var_dump() output, but not the actual memory management.



                    This may address some concerns why you see double instead of float shown in var_dump in some other machines.



                    Also, with or without xdebug, gettype still returns string(6) "double".






                    share|improve this answer


























                    • Very interesting! Thanks for pointing this out.

                      – L S
                      Dec 6 '17 at 16:40
















                    5














                    As of PHP 7.0.6 on Windows, comparing this command without xdebug:



                    $ php -r 'var_dump(28.4);'
                    float(28.4)


                    and with xdebug:



                    $ php -r 'var_dump(28.4);'
                    Command line code:1:
                    double(28.4)


                    Note that this only changes var_dump() output, but not the actual memory management.



                    This may address some concerns why you see double instead of float shown in var_dump in some other machines.



                    Also, with or without xdebug, gettype still returns string(6) "double".






                    share|improve this answer


























                    • Very interesting! Thanks for pointing this out.

                      – L S
                      Dec 6 '17 at 16:40














                    5












                    5








                    5







                    As of PHP 7.0.6 on Windows, comparing this command without xdebug:



                    $ php -r 'var_dump(28.4);'
                    float(28.4)


                    and with xdebug:



                    $ php -r 'var_dump(28.4);'
                    Command line code:1:
                    double(28.4)


                    Note that this only changes var_dump() output, but not the actual memory management.



                    This may address some concerns why you see double instead of float shown in var_dump in some other machines.



                    Also, with or without xdebug, gettype still returns string(6) "double".






                    share|improve this answer















                    As of PHP 7.0.6 on Windows, comparing this command without xdebug:



                    $ php -r 'var_dump(28.4);'
                    float(28.4)


                    and with xdebug:



                    $ php -r 'var_dump(28.4);'
                    Command line code:1:
                    double(28.4)


                    Note that this only changes var_dump() output, but not the actual memory management.



                    This may address some concerns why you see double instead of float shown in var_dump in some other machines.



                    Also, with or without xdebug, gettype still returns string(6) "double".







                    share|improve this answer














                    share|improve this answer



                    share|improve this answer








                    edited Dec 6 '17 at 17:22

























                    answered Jan 14 '17 at 12:39









                    SOFeSOFe

                    2,67032144




                    2,67032144













                    • Very interesting! Thanks for pointing this out.

                      – L S
                      Dec 6 '17 at 16:40



















                    • Very interesting! Thanks for pointing this out.

                      – L S
                      Dec 6 '17 at 16:40

















                    Very interesting! Thanks for pointing this out.

                    – L S
                    Dec 6 '17 at 16:40





                    Very interesting! Thanks for pointing this out.

                    – L S
                    Dec 6 '17 at 16:40











                    1














                    In PHP 7.0.14



                    function test(double $a) {
                    var_dump($a);
                    }
                    test(2.2111);


                    Returns "Fatal error: Uncaught TypeError: Argument 1 passed to test() must be an instance of double, float given".



                    function test(float $a) {
                    var_dump($a);
                    }
                    test(2.2111);


                    Prints 2.2111 to the screen.






                    share|improve this answer



















                    • 1





                      Only float is a valid type hint (see). When you type double instead, it is treated as an class name, and interpreter throws the exception, because it expects a variable with instance of the double class

                      – AterLux
                      Oct 18 '18 at 12:24
















                    1














                    In PHP 7.0.14



                    function test(double $a) {
                    var_dump($a);
                    }
                    test(2.2111);


                    Returns "Fatal error: Uncaught TypeError: Argument 1 passed to test() must be an instance of double, float given".



                    function test(float $a) {
                    var_dump($a);
                    }
                    test(2.2111);


                    Prints 2.2111 to the screen.






                    share|improve this answer



















                    • 1





                      Only float is a valid type hint (see). When you type double instead, it is treated as an class name, and interpreter throws the exception, because it expects a variable with instance of the double class

                      – AterLux
                      Oct 18 '18 at 12:24














                    1












                    1








                    1







                    In PHP 7.0.14



                    function test(double $a) {
                    var_dump($a);
                    }
                    test(2.2111);


                    Returns "Fatal error: Uncaught TypeError: Argument 1 passed to test() must be an instance of double, float given".



                    function test(float $a) {
                    var_dump($a);
                    }
                    test(2.2111);


                    Prints 2.2111 to the screen.






                    share|improve this answer













                    In PHP 7.0.14



                    function test(double $a) {
                    var_dump($a);
                    }
                    test(2.2111);


                    Returns "Fatal error: Uncaught TypeError: Argument 1 passed to test() must be an instance of double, float given".



                    function test(float $a) {
                    var_dump($a);
                    }
                    test(2.2111);


                    Prints 2.2111 to the screen.







                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered Feb 22 '18 at 12:18









                    OborotenOboroten

                    3518




                    3518








                    • 1





                      Only float is a valid type hint (see). When you type double instead, it is treated as an class name, and interpreter throws the exception, because it expects a variable with instance of the double class

                      – AterLux
                      Oct 18 '18 at 12:24














                    • 1





                      Only float is a valid type hint (see). When you type double instead, it is treated as an class name, and interpreter throws the exception, because it expects a variable with instance of the double class

                      – AterLux
                      Oct 18 '18 at 12:24








                    1




                    1





                    Only float is a valid type hint (see). When you type double instead, it is treated as an class name, and interpreter throws the exception, because it expects a variable with instance of the double class

                    – AterLux
                    Oct 18 '18 at 12:24





                    Only float is a valid type hint (see). When you type double instead, it is treated as an class name, and interpreter throws the exception, because it expects a variable with instance of the double class

                    – AterLux
                    Oct 18 '18 at 12:24


















                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f3280892%2fdifference-between-float-and-double-in-php%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Monofisismo

                    Angular Downloading a file using contenturl with Basic Authentication

                    Olmecas