2
0
Переглянути джерело

Fixes #342 - Zend_Locale_Format::getFloat does not handle exponential notation

Frank Brückner 11 роки тому
батько
коміт
fcac25d10c
2 змінених файлів з 7 додано та 4 видалено
  1. 2 4
      library/Zend/Locale/Format.php
  2. 5 0
      tests/Zend/Locale/FormatTest.php

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

@@ -256,10 +256,8 @@ class Zend_Locale_Format
         // Get correct signs for this locale
         $symbols = Zend_Locale_Data::getList($options['locale'],'symbols');
         // Change locale input to be default number
-        if ((strpos($input, $symbols['minus']) !== false) ||
-            (strpos($input, '-') !== false)) {
-            $input = strtr($input, array($symbols['minus'] => '', '-' => ''));
-            $input = '-' . $input;
+        if (($input[0] == $symbols['minus']) && ('-' != $input[0])) {
+            $input = '-' . substr($input, 1);
         }
 
         $input = str_replace($symbols['group'],'', $input);

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

@@ -152,6 +152,11 @@ class Zend_Locale_FormatTest extends PHPUnit_Framework_TestCase
         $this->assertEquals(-1234567.12345,   Zend_Locale_Format::getFloat(-1234567.12345  ));
         $this->assertEquals( 1234567.12345,   Zend_Locale_Format::getFloat( 1234567.12345  ));
 
+        $this->assertEquals( 0.01, Zend_Locale_Format::getFloat(  1e-2 ));
+        $this->assertEquals( 0.01, Zend_Locale_Format::getFloat( '1e-2'));
+        $this->assertEquals(-0.01, Zend_Locale_Format::getFloat( -1e-2 ));
+        $this->assertEquals(-0.01, Zend_Locale_Format::getFloat('-1e-2'));
+
         $options = array('locale' => 'de');
         $this->assertEquals(       0,         Zend_Locale_Format::getFloat(         '0',         $options));
         $this->assertEquals(-1234567,         Zend_Locale_Format::getFloat(  '-1234567',         $options));