ZF-5908: ::toNumber(-0.75, array('decimals' => 2)) == 0.75 -> should be -0.75 (with no bcmath extension)

Issue Type: Bug Created: 2009-02-27T08:47:11.000+0000 Last Updated: 2009-02-27T16:16:43.000+0000 Status: Resolved Fix version(s): - 1.8.0 (30/Apr/09)

Reporter: Sébastien Vanvelthem (belgattitude) Assignee: Thomas Weidner (thomas) Tags: - Zend_Locale

Related issues: Attachments:


Formatting of float number between 0 and -1 loose the minus sign : example talk by itself :

<pre class="highlight">
echo Zend_Locale_Format::toNumber(-0.75, array('precision'=> 2, 'locale' => new Zend_Locale('en_EN'))); // -> Gives 0.75 -> ERROR MUST BE -0.75
echo Zend_Locale_Format::toNumber(-1.75, array('precision'=> 2, 'locale' => new Zend_Locale('en_EN'))); // -> Gives -1.75 -> OK
echo Zend_Locale_Format::toNumber(0.75, array('precision'=> 2, 'locale' => new Zend_Locale('en_EN'))); // -> Gives 0.75 -> OK

No bcmath extension enabled.

I can't provide a clean patch, but have a look in Zend_Locale_Format::toNumber() and especially to Zend_Locale_Math_PhpMath::Comp() method, you'll see what happens there.

Probably something linked to scale (in my case defaultScale is null) or better to review the comparisons when scale is null.

Good luck

PS :

A simple workaround could be something like below (in the end of method Zend_Locale_Format::toNumber())

<pre class="highlight">
        // set negative sign
        if (call_user_func(Zend_Locale_Math::$comp, $value, 0) < 0) {
            if (iconv_strpos($format, '-') === false) {
                $format = $symbols['minus'] . $format;
            } else {
                $format = str_replace('-', $symbols['minus'], $format);

        // patched in a hurry by Seb
        if ($value < 0 && $format >= 0) $format = $symbols['minus'] . "$format";
        return (string) $format;


Posted by Thomas Weidner (thomas) on 2009-02-27T14:05:02.000+0000

Fixed with r14189

Posted by Sébastien Vanvelthem (belgattitude) on 2009-02-27T16:16:42.000+0000

Thanks Thomas.

Quickest fix ever :D

Thanks again.

Have you found an issue?

See the Overview section for more details.


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

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