You can use round()
to round your number to an integer, or to round off complex floating point numbers to a specific number of decimal places. This is accomplished by passing a second, optional parameter toround()
, telling it how many decimal places you want the number rounded to.
Here's an example:
// Round pi down from 3.1416...
$round = round(M_PI);
print $round; // prints 3
// This time, round pi to 4 places
$round_decimal = round(M_PI, 4);
print $round_decimal; // prints 3.1416
NOTE: M_PI
is a PHP constant that is equal to pi.