Coduo\PHPHumanizer\String\BinarySuffix::setSpecificPrecisionFormat PHP Method

setSpecificPrecisionFormat() protected method

Replaces the default ICU 56.1 decimal formats defined in $binaryPrefixes with ones that provide the same symbols but the provided number of decimal places.
protected setSpecificPrecisionFormat ( integer $precision )
$precision integer
    protected function setSpecificPrecisionFormat($precision)
    {
        if ($precision < 0) {
            throw new \InvalidArgumentException('Precision must be positive');
        }
        if ($precision > 3) {
            throw new \InvalidArgumentException('Invalid precision. Binary suffix converter can only represent values in ' . 'up to three decimal places');
        }
        $icuFormat = '#';
        if ($precision > 0) {
            $icuFormat .= str_pad('#.', 2 + $precision, '0');
        }
        foreach ($this->binaryPrefixes as $size => $unitPattern) {
            if ($size >= 1024) {
                $symbol = substr($unitPattern, strpos($unitPattern, ' '));
                $this->binaryPrefixes[$size] = $icuFormat . $symbol;
            }
        }
    }