Skip to content
Advertisement

PHP Undefined Constant PHP_ROUND_HALF_DOWN

I have some PHP code in a project I’m working on that uses PHP’s round function. On my localhost, I don’t include any quotes around my mode argument, stating it as just PHP_ROUND_HALF_DOWN. However, when pushing to my server I get the error message:

Use of undefined constant PHP_ROUND_HALF_DOWN - assumed 'PHP_ROUND_HALF_DOWN'
Warning (2): Wrong parameter count for round() [APP/views/helpers/time_left.php, line 14]

Now, when I add the single quotes to the mode argument, the first error goes away, however the “wrong parameter count” remains. I’m calling the function as follows:

$days = round(($difference/$day), 0, PHP_ROUND_HALF_DOWN);

Thanks for any and all help!

Advertisement

Answer

The rounding mode was added in PHP 5.3. Make sure you’re running at least that version.

You can see which version you’re running by placing the following in a PHP file:

var_dump(phpversion());
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement