Tuesday, June 21, 2016

Javascript's Round vs PHP's Round

Today I learned that by default PHP rounds differently than javascript.

PHP (using the default PHP_ROUND_HALF_UP)

php > echo round(-1.5);
"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."


"For negative numbers, if the decimal portion is exactly -0.5, the return value is the smallest integer that is greater than the number."