Issues

ZF-7712: Zend_XmlRpc_Value_Double rounds to 6 decimal digits

Issue Type: Bug Created: 2009-08-28T06:54:03.000+0000 Last Updated: 2010-02-23T09:57:12.000+0000 Status: Resolved Fix version(s): - 1.9.7 (11/Jan/10)

  • 1.10.2 (24/Feb/10)

Reporter: Lode Blomme (lode) Assignee: Matthew Weier O'Phinney (matthew) Tags: - Zend_XmlRpc_Client

Related issues: Attachments:

Description

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

Comments

Posted by Lars Strojny (lars) on 2009-08-28T07:09:53.000+0000

This is a bug due to a known behavior of sprintf(). See http://us2.php.net/manual/en/… for details. The solution would be to specify a specific precision for sprintf().

Posted by Lode Blomme (lode) on 2009-08-28T07:33:15.000+0000

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.

Posted by Lars Strojny (lars) on 2009-08-31T06:36:34.000+0000

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

Posted by Lode Blomme (lode) on 2009-09-08T07:49:12.000+0000

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 :

<pre class="highlight">
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);
    }
}

Posted by Lars Strojny (lars) on 2009-12-09T19:39:40.000+0000

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

Posted by Adam Kusmierz (raistlin) on 2010-02-17T10:54:34.000+0000

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:

<pre class="highlight">
49. $formatString = '%1.' . $precision . 'F';

Posted by Matthew Weier O'Phinney (matthew) on 2010-02-23T09:57:12.000+0000

Fixed in trunk and 1.10 release branch.

Have you found an issue?

See the Overview section for more details.

Copyright

© 2006-2016 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.

Contacts