diff --git a/Tests/convertTest.php b/Tests/convertTest.php index b4bd8c9..ed276bc 100644 --- a/Tests/convertTest.php +++ b/Tests/convertTest.php @@ -105,6 +105,13 @@ class test_convert extends PHPUnit_Framework_TestCase $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 () { $this->expectException ("Exception", diff --git a/convert.php b/convert.php index 29f78a3..31751c0 100644 --- a/convert.php +++ b/convert.php @@ -131,12 +131,17 @@ class convert 6 => 'E', // exa 7 => 'Z', // zetta 8 => 'Y');// yotta - for ($factor = 8 ; $factor >= -8 ; $factor--) + for ($factor = 8 ; $factor > -8 ; $factor--) { if (abs ($value) >= pow ($power, $factor)) break; } - if ($factor > 0) + if ($value == 0) + { + $display = 0; + $factor = 0; + } + elseif ($factor > 0) $display = $value / pow ($power, $factor); elseif ($factor < 0) $display = $value * pow ($power, -1 * $factor);