# Basics / Numeric type     Numeric type

Pages   0 from 91
Questions   0 from 142

Reset

Decimal (1, 0, -1, 10, 1452)
``` <?php echo 10; // Output 10 echo -1; // Output -1 echo 0; // Output 0 echo 1452; // Output 1452 ``` Octal (0600; 0100) This is Unix style access permision (identified by its leading zero)
``` <?php echo 0100; // 64 = 1*8^2 + 0*8^1 + 0*8^0 ``` Hexadecimal (0x123; 0XFF) Base 16 notation (identified by its leadgin 0x case-insensitive)
``` <?php echo 0x111; // 1*16^2 + 1*16^1 + 1*16^0 = 256 + 16 + 1 = 273 echo 0x112; // 1*16^2 + 1*16^1 + 2*16^0 = 256 + 16 + 2 = 274 echo 0x121; // 1*16^2 + 2*16^1 + 1*16^0 = 256 + 32 + 1 = 289 echo 0xFFF; // 15*16^2 + 15*16^1 + 15*16^0 = 3840 + 240 + 15 = 4095 ``` Be aware that the float data type is not always capable of representing numbers in the way you expect it to.
``` <?php echo ((0.1 + 0.7) * 10); // output 8 echo (int) ((0.1 + 0.7) * 10); // output 7 // This happens because the result of this simple arithmetic expression is stored internally as 7.999999 // instead of 8; when the value is converted to int, PHP simply truncates away the fractional part. ``` blueshoes.org

# Related Pages

Basic syntax
Numeric type
String type
Boolean type
Constants definition
Control structures
Reference

0% 100%

0 pages
1) How is store internally the following expression? <?php \$a = (0.2 + 0.5) * 10;

Decimal (1, 0, -1, 10, 1452)
``` <?php echo 10; // Output 10 echo -1; // Output -1 echo 0; // Output 0 echo 1452; // Output 1452 ``` Octal (0600; 0100) This is Unix style access permision (identified by its leading zero)
``` <?php echo 0100; // 64 = 1*8^2 + 0*8^1 + 0*8^0 ``` Hexadecimal (0x123; 0XFF) Base 16 notation (identified by its leadgin 0x case-insensitive)
``` <?php echo 0x111; // 1*16^2 + 1*16^1 + 1*16^0 = 256 + 16 + 1 = 273 echo 0x112; // 1*16^2 + 1*16^1 + 2*16^0 = 256 + 16 + 2 = 274 echo 0x121; // 1*16^2 + 2*16^1 + 1*16^0 = 256 + 32 + 1 = 289 echo 0xFFF; // 15*16^2 + 15*16^1 + 15*16^0 = 3840 + 240 + 15 = 4095 ``` Be aware that the float data type is not always capable of representing numbers in the way you expect it to.
``` <?php echo ((0.1 + 0.7) * 10); // output 8 echo (int) ((0.1 + 0.7) * 10); // output 7 // This happens because the result of this simple arithmetic expression is stored internally as 7.999999 // instead of 8; when the value is converted to int, PHP simply truncates away the fractional part. ``` blueshoes.org

Programming

References