Zend Framework

Zend_XmlRpc_Value_Double rounds to 6 decimal digits

Details

  • Type: Bug Bug
  • Status: Resolved Resolved
  • Priority: Major Major
  • Resolution: Fixed
  • Affects Version/s: 1.9.2
  • Fix Version/s: 1.9.7, 1.10.2
  • Component/s: Zend_XmlRpc_Client
  • Labels:
    None

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

Activity

Hide
Lars Strojny added a comment -

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

Show
Lars Strojny added a comment - This is a bug due to a known behavior of sprintf(). See http://us2.php.net/manual/en/function.sprintf.php#92124 for details. The solution would be to specify a specific precision for sprintf().
Hide
Lode Blomme added a comment - - edited

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.

Show
Lode Blomme added a comment - - edited 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.
Hide
Lars Strojny added a comment -

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

Show
Lars Strojny added a comment - Fixed in r17921. Thank you for taking time to write us!
Hide
Lode Blomme added a comment -

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);
    }
}
Show
Lode Blomme added a comment - 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);
    }
}
Hide
Lars Strojny added a comment -

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

Show
Lars Strojny added a comment - Fixed in trunk (r19562) and 1.9 release branch (r19563). We now trim trailing "0"s when building the XML envelope
Hide
Adam Kusmierz added a comment -

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:

Zend/XmlRpc/Value/Double
49. $formatString = '%1.' . $precision . 'F';
Show
Adam Kusmierz added a comment - 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:
Zend/XmlRpc/Value/Double
49. $formatString = '%1.' . $precision . 'F';
Hide
Matthew Weier O'Phinney added a comment -

Fixed in trunk and 1.10 release branch.

Show
Matthew Weier O'Phinney added a comment - Fixed in trunk and 1.10 release branch.

People

Vote (0)
Watch (1)

Dates

  • Created:
    Updated:
    Resolved: