round

(PHP 3, PHP 4 >= 4.0.0)

round -- Rounds a float

Description

float round ( float val [, int precision])

Returns the rounded value of val to specified precision (number of digits after the decimal point). precision can also be negative or zero (default).

V²straha

PHP doesn't handle strings like "12,300.2" correctly by default. See converting from strings.

$foo = round(3.4);  // $foo == 3.0
$foo = round(3.5);  // $foo == 4.0
$foo = round(3.6);  // $foo == 4.0
$foo = round(3.6, 0);  // equivalent with above

$foo = round(1.95583, 2);  // $foo == 1.96

$foo = round(1241757, -3);  // $foo == 1242000

Poznßmka: The precision parameter is only available in PHP 4.

See also ceil() and floor().