ZF-7712: Zend_XmlRpc_Value_Double rounds to 6 decimal digits


When I make a request with a double parameter like 3.39412716 , the value is sent as 3.394127 .

The rounding takes place in Zend/XmlRpc/Value/Double.php on line 48 : {{$this->_value = sprintf('%f',(float)$value); // Make sure this value is float (double) and without the scientific notation}}


This is a bug due to a known behavior of sprintf(). See… for details. The solution would be to specify a specific precision for sprintf().

Wouldn't it be possible to detect the precision of the input, and adding this to the sprintf command? Simply increasing the precision would result in added zeros at the end. That's not desirable.

Fixed in r17921. Thank you for taking time to write us!

This solution has the downside of adding trailing zeros to the double value in XML. If you have a message with alot of double values, this can add up to quite some extra data to be tranfered. Therefore I propose an addition to eliminate those trailing zeros :

if (strstr($num, '.')) {
    $num = trim($num, '0');
    if ($num[0] == '.') {
        $num = '0' . $num;
    if ($num[strlen($num) - 1] == '.') {
        $num = substr($num, 0, strlen($num) - 1);

Fixed in trunk (r19562) and 1.9 release branch (r19563). We now trim trailing "0"s when building the XML envelope

You can't use printf's schema "f", bacause it's locale aware. On Windows, this function returns float, but rounded to decimal part (ie. 1 instead 1.123).

You should use "F" instead:

49. $formatString = '%1.' . $precision . 'F';

Fixed in trunk and 1.10 release branch.