Bytes formatter unit size setting


#1

We are using the Download (GitHub - matomo-org/plugin-Bandwidth: Monitor Bandwidth for each page, download, and measure overall traffic in bytes) module for showing downloaded traffic. But we see that the formatter uses a factor 1024 for translating bytes to Megabytes and Terabytes.

But we would like to use the factor 1000. Because we have another tool for calculating the used bandwidth, and there the units factor is 1000. So at this time we have a difference.

If this could be a setting in the config.ini.php file so we can override this value.

The function that should read this setting is:
core/Metrics/Formatter.php
in the function:


protected function getPrettySizeFromBytesWithUnit($size, $unit = null, $precision = 1)
    {
        $units = array('B', 'K', 'M', 'G', 'T');
        $numUnits = count($units) - 1;

        $currentUnit = null;
        foreach ($units as $idx => $currentUnit) {
            if ($unit && $unit !== $currentUnit) {
                $size = $size / 1024;
            } elseif ($unit && $unit === $currentUnit) {
                break;
            } elseif ($size >= 1024 && $idx != $numUnits) {
                $size = $size / 1024;
            } else {
                break;
            }
        }

        $size = round($size, $precision);

        return array($size, $currentUnit);
    }

Could this be implemented in a next release? Would be nice