i

PHP Tutorial

PHP Numbers

Numbers are an essential data type in PHP. Most of the data and information we deal with for complex programs require amounts. There are many types of numeric data that we can use in php and mathematical functions. To print a number in php, you can write echo 40; and it will print 40. You can make the number negative, i.e. -40 or decimal like 40.37. 

  • Integer – an Integer is a whole number without any decimal part, and it can include negative numeric values also. A non-decimal number between -2147483648 and 2147483647 is an integer value in php.

  • Float – Float is the numbers with decimal values or in an exponential form such as 4.5, 647.3, 2.567, 8.34E+2, 4.23E-1 are all float values, and it can store amounts up to 1.7976931348623E+308 with a precision of 14 digits.

  • Infinity – A numeric value more significant than PHP_FLOAT_MAX is an infinite numeric value, and you can check the value is finite or infinite using is_finite() or is_infinite() functions.

  • NaN – For a mathematical operation that is not possible NaN, i.e. Not a number is present in php. You can check if the value is not a number through is_nan() function.

  • Casting – If you need to throw a numeric value into another data type, you can use casting functions such as (int), (integer) or intval(). You can convert string values or float values to integers using these functions.