]> source.dussan.org Git - nextcloud-server.git/commitdiff
Correctly round bytes when converted from human readable format
authorVincent Petry <pvince81@owncloud.com>
Mon, 17 Mar 2014 11:15:12 +0000 (12:15 +0100)
committerVincent Petry <pvince81@owncloud.com>
Mon, 17 Mar 2014 11:15:12 +0000 (12:15 +0100)
Instead of leave two decimal places which is confusing, round the byte
values correctly to the closest byte.

lib/private/helper.php
tests/lib/helper.php

index 0b1a26bbecdfba70088ca199defe21af623f1108..807fa84963733140f3cfccbec81d2578825045bd 100644 (file)
@@ -308,7 +308,7 @@ class OC_Helper {
 
        /**
         * @brief Make a computer file size
-        * @param string $str file size in a fancy format
+        * @param string $str file size in human readable format
         * @return int a file size in bytes
         *
         * Makes 2kB to 2048.
@@ -338,7 +338,7 @@ class OC_Helper {
                        $bytes *= $bytes_array[$matches[1]];
                }
 
-               $bytes = round($bytes, 2);
+               $bytes = round($bytes);
 
                return $bytes;
        }
index 4311215795cfcf8f085e3b0a2bb969e40dd870b3..0943e6bc1b9db79f8b16743a4eeaaa0190d74aaa 100644 (file)
@@ -23,6 +23,7 @@ class Test_Helper extends PHPUnit_Framework_TestCase {
                        array('0 B', 0),
                        array('1 kB', 1024),
                        array('9.5 MB', 10000000),
+                       array('1.3 GB', 1395864371),
                        array('465.7 GB', 500000000000),
                        array('454.7 TB', 500000000000000),
                        array('444.1 PB', 500000000000000000),
@@ -41,8 +42,9 @@ class Test_Helper extends PHPUnit_Framework_TestCase {
                return array(
                        array(0.0, "0 B"),
                        array(1024.0, "1 kB"),
+                       array(1395864371.0, '1.3 GB'),
                        array(9961472.0, "9.5 MB"),
-                       array(500041567436.8, "465.7 GB"),
+                       array(500041567437.0, "465.7 GB"),
                );
        }