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

Issue Type: Bug Created: 2009-07-23T03:08:47.000+0000 Last Updated: 2009-07-23T05:09:02.000+0000 Status: Resolved Fix version(s): - 1.9.0 (31/Jul/09)

Reporter: Zoran Lazic (zoki) Assignee: Thomas Weidner (thomas) Tags: - Zend_Currency

Related issues: Attachments:


Zend_Currency::toCurrency() returns wrong number when working with floats lower than 1.0E-5

Code example:

<pre class="literal">
$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


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:

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.

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.