[Previous] [Contents] [Next]

Integer and Float Functions

Apart from the basic operators +, -, /, *, and %, PHP provides the usual array of mathematical library functions. In this section, we present some of the library functions that are used with integer and float numbers.

Absolute Value

The absolute value of an integer or a float can be found with the abs( ) function.

abs function

This function returns the absolute value of number. If the argument number is of type float, the return type is also float, otherwise it is integer

abs function syntax

This function accepts one parameter "the numeric value" (float or integer) to process

number abs ( mixed number )
integer abs(integer number)
float abs(float number)

abs function examples

The following examples show the result of abs( ) on floats and integers:

echo abs(-1);
     // prints 1

echo abs(1);
     // prints 1

echo abs(-145.89);
     // prints 145.89

echo abs(145.89);
     // prints 145.89

[Previous] [Contents] [Next]