Req #79073 [NEW]: round() does not have PHP_ROUND_UP or PHP_ROUND_DOWN modes
| From: | objecttothis at gmail dot com | Date: | Tue, 07 Jan 2020 10:48:54 +0000 |
| Subject: | Req #79073 [NEW]: round() does not have PHP_ROUND_UP or PHP_ROUND_DOWN modes | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-224747@lists.php.net to get a copy of this message | ||
From: objecttothis at gmail dot com
Operating system: FreeBSD 11.2
PHP version: 7.4.1
Package: *Math Functions
Bug Type: Feature/Change Request
Bug description:round() does not have PHP_ROUND_UP or PHP_ROUND_DOWN modes
Description:
------------
There is no mode in round() that always rounds up or always rounds down.
To do this you have to use ceil() or floor() which do not use
precision, so the result will always be an integer. If PHP_ROUND_UP and
PHP_ROUND_DOWN modes were added, it would resolve this problem.
Test script:
---------------
<?php
function round_up($number, $precision = 2)
{
$fig = (int) str_pad('1', $precision, '0');
return (ceil($number * $fig) / $fig);
}
function round_down($number, $precision = 2)
{
$fig = (int) str_pad('1', $precision, '0');
return (floor($number * $fig) / $fig);
}
?>
--
Edit bug report at https://bugs.php.net/bug.php?id=79073&edit=1
--
Fix committed: https://bugs.php.net/fix.php?id=79073&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=79073&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=79073&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=79073&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=79073&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=79073&r=support
Expected behavior: https://bugs.php.net/fix.php?id=79073&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=79073&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=79073&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=79073&r=globals
PHP version support discontinued: https://bugs.php.net/fix.php?id=79073&r=phptooold
Daylight Savings: https://bugs.php.net/fix.php?id=79073&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=79073&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=79073&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=79073&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=79073&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=79073&r=mysqlcfg