parse numbers terminated with decimal separator
This commit is contained in:
parent
76c2de0317
commit
4225f36b86
@ -516,7 +516,7 @@ class NumberFormatter
|
||||
$groupSep = $this->getAttribute(self::GROUPING_USED) ? ',' : '';
|
||||
|
||||
// Any string before the numeric value causes error in the parsing
|
||||
if (preg_match("/^-?(?:\.\d++|([\d{$groupSep}]++)(?:\.\d++)?)/", $value, $matches)) {
|
||||
if (preg_match("/^-?(?:\.\d++|([\d{$groupSep}]++)(?:\.\d*+)?)/", $value, $matches)) {
|
||||
$value = $matches[0];
|
||||
$position = \strlen($value);
|
||||
if ($error = $groupSep && isset($matches[1]) && !preg_match('/^\d{1,3}+(?:(?:,\d{3})++|\d*+)$/', $matches[1])) {
|
||||
|
@ -654,6 +654,7 @@ abstract class AbstractNumberFormatterTest extends TestCase
|
||||
array('-123,4567', false, '->parse() does not parse when invalid grouping used.', 9),
|
||||
array('-123,,456', false, '->parse() does not parse when invalid grouping used.', 4),
|
||||
array('-123,,456', -123.0, '->parse() parses when grouping is disabled.', 4, false),
|
||||
array('239.', 239.0, '->parse() parses when string ends with decimal separator.', 4, false),
|
||||
);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user