MemoryRefresh!

Numeric type



Questions 1 Answers 0%

Pages   0 from 51
Questions   0 from 84

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.
http://www.blueshoes.org
Questions

Related pages

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


0% 100%
 
 
0 pages 51 pages
1) What the output will be for the following code? <?php echo (int) ((0.1 + 0.7) * 10);




2) What the output will be for the following code? <?php echo (0.1 + 0.7) * 10;




Last Review: n/a   Passed: n/a   Reviews: n/a   Next Review: n/a  


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.
http://www.blueshoes.org



More from Php

Basics
Variables
Operators
Function
Array
String
Streams
Uncategorized


More from Programming

Php
jQuery




Powered by minte9.com