Explorar o código

[ZF-9160] Zend_Locale:

- fixed zero precision bug

git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@21110 44c647ce-9c0f-0410-b52a-842ac1e357ba
thomas %!s(int64=16) %!d(string=hai) anos
pai
achega
5bc3757285
Modificáronse 2 ficheiros con 12 adicións e 0 borrados
  1. 4 0
      library/Zend/Locale/Format.php
  2. 8 0
      tests/Zend/Locale/FormatTest.php

+ 4 - 0
library/Zend/Locale/Format.php

@@ -270,6 +270,10 @@ class Zend_Locale_Format
             if (strlen($pre) >= $options['precision']) {
             if (strlen($pre) >= $options['precision']) {
                 $input = substr($input, 0, strlen($input) - strlen($pre) + $options['precision']);
                 $input = substr($input, 0, strlen($input) - strlen($pre) + $options['precision']);
             }
             }
+
+            if (($options['precision'] == 0) && ($input[strlen($input) - 1] == '.')) {
+                $input = substr($input, 0, -1);
+            }
         }
         }
 
 
         return $input;
         return $input;

+ 8 - 0
tests/Zend/Locale/FormatTest.php

@@ -1074,4 +1074,12 @@ class Zend_Locale_FormatTest extends PHPUnit_Framework_TestCase
         $options = array('locale' => 'de_AT');
         $options = array('locale' => 'de_AT');
         $this->assertEquals('0,567', Zend_Locale_Format::toNumber(.567, $options));
         $this->assertEquals('0,567', Zend_Locale_Format::toNumber(.567, $options));
     }
     }
+
+    /**
+     * @group ZF-9160
+     */
+    public function testGetNumberWithZeroPrecision()
+    {
+        $this->assertEquals(1234, Zend_Locale_Format::getNumber('1234.567', array('locale' => 'en_US', 'precision' => 0)));
+    }
 }
 }