Convert : if the value is 0 for humansize, return 0.000

git-svn-id: https://svn.fournier38.fr/svn/ProgSVN/trunk@5731 bf3deb0d-5f1a-0410-827f-c0cc1f45334c
This commit is contained in:
2019-11-15 21:34:10 +00:00
parent 78922b2521
commit 94191fa144
2 changed files with 14 additions and 2 deletions

View File

@@ -105,6 +105,13 @@ class test_convert extends PHPUnit_Framework_TestCase
$this->assertSame ($res, "-12.35kB"); $this->assertSame ($res, "-12.35kB");
} }
public function test_humanSize_8 ()
{
$res = \convert::humanSize (0, 2);
$this->assertSame ($res, "0.00B");
}
public function test_humanSize_error1 () public function test_humanSize_error1 ()
{ {
$this->expectException ("Exception", $this->expectException ("Exception",

View File

@@ -131,12 +131,17 @@ class convert
6 => 'E', // exa 6 => 'E', // exa
7 => 'Z', // zetta 7 => 'Z', // zetta
8 => 'Y');// yotta 8 => 'Y');// yotta
for ($factor = 8 ; $factor >= -8 ; $factor--) for ($factor = 8 ; $factor > -8 ; $factor--)
{ {
if (abs ($value) >= pow ($power, $factor)) if (abs ($value) >= pow ($power, $factor))
break; break;
} }
if ($factor > 0) if ($value == 0)
{
$display = 0;
$factor = 0;
}
elseif ($factor > 0)
$display = $value / pow ($power, $factor); $display = $value / pow ($power, $factor);
elseif ($factor < 0) elseif ($factor < 0)
$display = $value * pow ($power, -1 * $factor); $display = $value * pow ($power, -1 * $factor);