ZF-7359: Zend_Currency::toCurrency() returning wrong numbers when working with small floats


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


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.

Fixed with r16998

For details to this php bug see:

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.