-
-
Save DASPRiD/3005056 to your computer and use it in GitHub Desktop.
Float and NumberFormatter oddity
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$locale = $this->locale; | |
$fmt = new NumberFormatter($locale, NumberFormatter::DECIMAL); | |
if (intl_is_failure($fmt->getErrorCode())) { | |
throw new Exception\InvalidArgumentException("Invalid locale string given"); | |
} | |
$parsedFloat = $fmt->parse($value, NumberFormatter::TYPE_DOUBLE, $position); | |
if (intl_is_failure($fmt->getErrorCode()) || $position < strlen($value)) { | |
$this->error(self::NOT_FLOAT); | |
return false; | |
} |
F
$value: string(3) "1.3"
$parsedFloat: float(13)
$position: int(3)
F
$value: string(6) "1000.3"
$parsedFloat: float(10003)
$position: int(6)
F
$value: string(7) "1,000.3"
$parsedFloat: float(1.0003)
$position: int(7)
F
$value: string(8) "1 000,3"
$parsedFloat: float(1000.3)
$position: int(7)
F
$value: string(3) "1,3"
$parsedFloat: float(13)
$position: int(3)
F
$value: string(6) "1000,3"
$parsedFloat: float(10003)
$position: int(6)
F
$value: string(7) "1.000,3"
$parsedFloat: float(1.0003)
$position: int(7)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Failed asserting that true matches expected false.
/Users/cmartin/Sites/zf2/tests/Zend/Validator/FloatTest.php:169
Failed asserting that true matches expected false.
/Users/cmartin/Sites/zf2/tests/Zend/Validator/FloatTest.php:169
Failed asserting that true matches expected false.
/Users/cmartin/Sites/zf2/tests/Zend/Validator/FloatTest.php:169
Failed asserting that false matches expected true.
/Users/cmartin/Sites/zf2/tests/Zend/Validator/FloatTest.php:191
Failed asserting that true matches expected false.
/Users/cmartin/Sites/zf2/tests/Zend/Validator/FloatTest.php:213
Failed asserting that true matches expected false.
/Users/cmartin/Sites/zf2/tests/Zend/Validator/FloatTest.php:213
Failed asserting that true matches expected false.
/Users/cmartin/Sites/zf2/tests/Zend/Validator/FloatTest.php:213
with this code: