Logo

Programming-Idioms

History of Idiom 81 > diff from v26 to v27

Edit summary for version 27 by :
[PHP] cast to int

Version 26

2016-03-04, 13:46:57

Version 27

2016-03-04, 21:50:36

Idiom #81 Round floating point number to integer

Declare integer y and initialize it with the rounded value of floating point number x .
Ties (when the fractional part of x is exactly .5) must be rounded up (to positive infinity).

Idiom #81 Round floating point number to integer

Declare integer y and initialize it with the rounded value of floating point number x .
Ties (when the fractional part of x is exactly .5) must be rounded up (to positive infinity).

Code
$y = round($x);
Code
$y = (int) round($x);
Doc URL
http://php.net/manual/en/function.round.php
Doc URL
http://php.net/manual/en/function.round.php