ZF-8009: Zend_Measure_Abstract forces precision in setType()

Issue Type: Bug Created: 2009-10-03T07:10:14.000+0000 Last Updated: 2009-10-06T12:02:30.000+0000 Status: Resolved Fix version(s): - 1.10.0 (27/Jan/10)

Reporter: Jeremy Kendall (jeremykendall) Assignee: Thomas Weidner (thomas) Tags: - Zend_Measure

Related issues: Attachments:


I use Zend_Measure in one of my projects, and after upgrading from ZF 1.8.x to ZF 1.9.3, I began to get unexpected results.

In ZF 1.8.x, I could convert from measure A to measure B and receive a decimal number with the fractional part intact. I can no longer do that in 1.9.3. For example, in 1.8.x, the following returns 3.3100000000000000000000000 m:

$unit = new Zend_Measure_Length(231, Zend_Measure_Length::CENTIMETER, $locale); $unit2 = new Zend_Measure_Length(1, Zend_Measure_Length::METER, $locale);

$sum = $unit->add($unit2);


echo $sum;

The same code returns 3 m when using 1.9.3.

The culprit turns out to be a change in Zend_Measure_Abstract::setType() in REV 15906. In REV 15906 (included in ZF 1.9.x), setType() forces rounding to the precision of the provided value. Since the values in the code example above do not have decimal fractions, the returned value is rounded to a precision of 0 (Zend_Locale_Math::round($value, $prec) on line 292. Precision is set to 0 on line 240 and changes only if strpos($this->_value, '.') !== false (line 242). This makes the $round parameter in Zend_Measure_Abstract::getValue() (almost) worthless, since I don't have any control over the rounding precision in Zend_Measure_Abstract::setType() (unless I pass a measure with a decimal fraction). Very frustrating, very confusing, and unless I missed something, this is undocumented behavior.

Is this a bug or a feature? If it's a feature, could someone explain how this behavior is preferable to the behavior in ZF 1.8.x?


Posted by Thomas Weidner (thomas) on 2009-10-06T12:02:30.000+0000

Fixed withr18493. Note that the returned value from 1.8 is also wrong.

Have you found an issue?

See the Overview section for more details.


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

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