Name
round
Synopsis
double round(doublenumber
[, intprecision
])
Returns the integer value nearest to
number
at the
precision
number of decimal places. The
default for precision is 0
(integer rounding). Note that this function provides proper
rounding—odd whole numbers are rounded up on a .5, even whole
numbers are rounded down on a .5. That is:
$first = round(1.5); // $first is 2 $second = round(2.5); // $second is also 2!
If you want the rounding taught to you in grade school, either
add a small number (smaller than the precision you’re after), or, if
you’re using whole numbers, add .5 and call floor( )
on the result.
Get Programming PHP, 2nd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.