src/Encoder/FloatEncoder.php
private function encodeFloat($float, $precision)
    {
        $log = (int) floor(log(abs($float), 10));

        if ($log > -5 && abs($float) < self::FLOAT_MAX && abs($log) < $precision) {
            return $this->formatFloat($float, $precision - $log - 1);
        }

        // Deal with overflow that results from rounding
        $log += (int) (round(abs($float) / 10 ** $log, $precision - 1) / 10);
        $string = $this->formatFloat($float / 10 ** $log, $precision - 1);

        return sprintf('%sE%+d', $string, $log);
    }
private function encodeFloat($float, $precision)
    {
        $log = (int) floor(log(abs($float), 10));

        if ($log > -5 && abs($float) < self::FLOAT_MAX && abs($log) < $precision) {
            return $this->formatFloat($float, $precision - $log - 1);
        }

        // Deal with overflow that results from rounding
        $log += (int) (round(abs($float) / 10 ** $log, $precision - 1) / 10);
        $string = $this->formatFloat($float / 10 ** $log, $precision - 1);

        return sprintf('%sE%+d', $string, $log);
    }
private function encodeFloat ( $ float , $ precision ) { $ log = ( int ) floor ( log ( abs ( $ float ) , 10 ) ) ; if ( $ log > - 5 && abs ( $ float ) < self :: FLOAT_MAX && abs ( $ log ) < $ precision ) { return $ this -> formatFloat ( $ float , $ precision - $ log - 1 ) ; } // Deal with overflow that results from rounding $ log += ( int ) ( round ( abs ( $ float ) / 10 ** $ log , $ precision - 1 ) / 10 ) ; $ string = $ this -> formatFloat ( $ float / 10 ** $ log , $ precision - 1 ) ; return sprintf ( '%sE%+d' , $ string , $ log ) ; }
Encodes the number using a floating point representation.
@param float $float The number to encode
@param int $precision The maximum precision of encoded floats
@return string The PHP code representation for the number
Encodes the number using a floating point representation .