-->

  • PHP numbers with integers


    PHP numbers with integers

    PHP Numbers


    You must have noticed one thing that whenever we take the numbers in the identification, then its conversion becomes automatic Or we can say that whatever number we give through Varible, the data type of the number is automatically correct according to its data type.Then, if you assign a string to the same variable, the type will change to a string. PHP numbers with integers

    This automatic conversion can sometimes break your code.


    PHP Integers

    An integer is a number without any decimal part.

    2, 256, -256, 10358, -179567 are all integers. While 7.56, 10.0, 150.67 are floats.


    So, an integer data type is a non-decimal number between -2147483648 and 2147483647. A value greater (or lower) than this, will be stored as float, because it exceeds the limit of an integer.

    Another important thing to know is that even if 4 * 2.5 is 10, the result is stored as float, because one of the operands is a float (2.5).



    Here are some rules for integers:



    • An integer must have at least one digit
    • An integer must not have a decimal point
    • An integer can be either positive or negative
    • Integers can be specified in three formats: decimal (10-based), hexadecimal (16-based - prefixed with 0x) or octal (8-based - prefixed with 0)


    PHP has the following functions to check if the type of a variable is integer:



    • is_int()
    • is_integer() - alias of is_int()
    • is_long() - alias of is_int()


    Integer Data Type Check 


    Example 

    <!DOCTYPE html>
    <html>
    <head>

    <title> PHP numbers with integers </title>

    </head>
    <body>

    <h1> </h1>


    <?php

    //  check if the type of a variable is integer
    $x = 574892;
    var_dump(is_int($x));

    echo "<br>";

    // check again

    $z = 54.2;
    var_dump(is_int($z));



    ?>


    </body>
    </html>





    bool(true)
    bool(false)



    NOTE :- Video on This Topic :- Soon





    Have a Nice Stay Here : - )


  • 0 comments:

    Post a Comment

    For Any Tech Updates, Hacking News, Internet, Computer, Technology and related to IT Field Articles Follow Our Blog.