private function formatValue($value, $precision)
    {
        $formatted = sprintf("%0.${precision}F", $value);

        if ($this->hasAutomaticPrecision()) {
            // [0 => integer part, 1 => fractional part].
            $formattedParts = explode('.', $formatted);

            if (isset($formattedParts[1])) {
                // Strip trailing 0s in fractional part.
                if (!$formattedParts[1] = chop($formattedParts[1], '0')) {
                    // Remove fractional part.
                    unset($formattedParts[1]);
                }

                $formatted = join('.', $formattedParts);
            }
        }

        return $formatted;
    }