Menu Samaritan's Purse

ROUND

Rounds a float

SYNTAX

round ( float $val [, int $precision = 0 [, int $mode = PHP_ROUND_HALF_UP ]] ) : float

PARAMETERS

val

The value to round.

precision

The optional number of decimal digits to round to. If the precision is positive, the rounding will occur after the decimal point. If the precision is negative, the rounding will occur before the decimal point. If the absolute value of the precision is greater than or equal to the number of digits, the result of the rounding is equal to 0

mode

Use one of the following constants to specify the mode in which rounding occurs.

CONSTANTS DESCRIPTION
PHP_ROUND_HALF_UP Round val up to precision decimal places away from zero, when it is half way there. Making 1.5 into 2 and -1.5 into -2.
PHP_ROUND_HALF_DOWN Round val down to precision decimal places towards zero, when it is half way there. Making 1.5 into 1 and -1.5 into -1.
PHP_ROUND_HALF_EVEN Round val to precision decimal places towards the nearest even value.
PHP_ROUND_HALF_ODD Round val to precision decimal places towards the nearest odd value.

RETURN

The value rounded to the given precision as a float.

EXAMPLES

VAL | DOWN

1

VAL | UP

2

PRECISION

-5: 0
-4: 10000
-3: 6000
-2: 5600
-1: 5560
0: 5556
1: 5555.6
2: 5555.56
3: 5555.556
4: 5555.5555

MODE | PHP_ROUND_HALF_UP

-2
2

MODE | PHP_ROUND_HALF_DOWN

-1
1

MODE | PHP_ROUND_HALF_EVEN

-2
2

MODE | PHP_ROUND_HALF_ODD

-1
1

PHP