From: soneta dot kumar at gmail dot com
Operating system: All
PHP version: 5.3.14
Package: *Math Functions
Bug Type: Feature/Change Request
Bug description:dec_ceil is wrong
Description:
------------
function ceil_dec($number,$precision,$separator)
{
$numberpart=explode($separator,$number);
$numberpart[1]=substr_replace($numberpart[1],$separator,$precision,0);
if($numberpart[0]>=0)
{$numberpart[1]=ceil($numberpart[1]);}
else
{$numberpart[1]=floor($numberpart[1]);}
$ceil_number= array($numberpart[0],$numberpart[1]);
return implode($separator,$ceil_number);
}
echo ceil_dec(1.019,2,".");
// Actual output = 1.2
// Expected output = 1.02
Test script:
---------------
This is solution :
function ceil_dec($number,$precision,$separator='.')
{
$appendZero = false;
$numberpart=explode($separator,$number);
$numberpart[1]=substr_replace($numberpart[1],$separator,$precision,0);
if($numberpart[1][0] == 0) { $appendZero = true;}
if($numberpart[0]>=0)
{$numberpart[1]=ceil($numberpart[1]);}
else
{$numberpart[1]=floor($numberpart[1]);}
if($appendZero){ $numberpart[1] = (int) '0'.$numberpart[1];}
$ceil_number= array($numberpart[0],$numberpart[1]);
return implode($separator,$ceil_number);
}
Expected result:
----------------
// Expected output = 1.02
Actual result:
--------------
// Expected output = 1.2
--
Edit bug report at https://bugs.php.net/bug.php?id=62538&edit=1
--
Try a snapshot (PHP 5.4):
https://bugs.php.net/fix.php?id=62538&r=trysnapshot54
Try a snapshot (PHP 5.3):
https://bugs.php.net/fix.php?id=62538&r=trysnapshot53
Try a snapshot (trunk):
https://bugs.php.net/fix.php?id=62538&r=trysnapshottrunk
Fixed in SVN:
https://bugs.php.net/fix.php?id=62538&r=fixed
Fixed in SVN and need be documented:
https://bugs.php.net/fix.php?id=62538&r=needdocs
Fixed in release:
https://bugs.php.net/fix.php?id=62538&r=alreadyfixed
Need backtrace:
https://bugs.php.net/fix.php?id=62538&r=needtrace
Need Reproduce Script:
https://bugs.php.net/fix.php?id=62538&r=needscript
Try newer version:
https://bugs.php.net/fix.php?id=62538&r=oldversion
Not developer issue:
https://bugs.php.net/fix.php?id=62538&r=support
Expected behavior:
https://bugs.php.net/fix.php?id=62538&r=notwrong
Not enough info:
https://bugs.php.net/fix.php?id=62538&r=notenoughinfo
Submitted twice:
https://bugs.php.net/fix.php?id=62538&r=submittedtwice
register_globals:
https://bugs.php.net/fix.php?id=62538&r=globals
PHP 4 support discontinued:
https://bugs.php.net/fix.php?id=62538&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=62538&r=dst
IIS Stability:
https://bugs.php.net/fix.php?id=62538&r=isapi
Install GNU Sed:
https://bugs.php.net/fix.php?id=62538&r=gnused
Floating point limitations:
https://bugs.php.net/fix.php?id=62538&r=float
No Zend Extensions:
https://bugs.php.net/fix.php?id=62538&r=nozend
MySQL Configuration Error:
https://bugs.php.net/fix.php?id=62538&r=mysqlcfg