ZF-7359: Zend_Currency::toCurrency() returning wrong numbers when working with small floats
Description
Zend_Currency::toCurrency() returns wrong number when working with floats lower than 1.0E-5
Code example:
$zendCurrency = new Zend_Currency("USD", "en_US");
$value = 1.0E-4; // 0.0001
echo $zendCurrency->toCurrency($value) ; // outputs $0.00
$value = 1.0E-5; // 0.00001 from -5 it gets wrong
echo $zendCurrency->toCurrency($value) ; // outputs $1.0 - WRONG should be 0.00
Comments
Posted by Thomas Weidner (thomas) on 2009-07-23T03:38:38.000+0000
The reason to this problem is based on PHP itself.
The scientific value "1.0E-4" is automatically converted to float "0.0001" by php. But the scientific value "1.0E-5" is not converted.
As Zend_Currency can not handle scientific numbers for now you see the above mentioned result. You can try this yourself by doing a var_dump on your inputs.
Posted by Thomas Weidner (thomas) on 2009-07-23T05:00:12.000+0000
Fixed with r16998
For details to this php bug see: http://bugs.php.net/bug.php?id=43053
Posted by Dolf Schimmel (Freeaqingme) (freak) on 2009-07-23T05:08:12.000+0000
Why don't you add a line like this to Zend_Currency::toCurrency(). All unittests seem to pass. ```
Edit: Didn't see Thomas' second comment before posting mine.