This is a (multiple allowed):
[ ] feature-discussion (RFC)
CakePHP Version: 3.5.0
Please check issue #10873 - it's the same problem, this time detected on decimals.
intl.default_locale is set to da_DK.
In bootstrap.php I have the following:
Cake\I18n\Number::config('da_DK', \NumberFormatter::DECIMAL);
Type::build('decimal')
->useLocaleParser();
This actually works OK, although it fails when:
47500 is enteredFormHelper as 47.500 which is correct according to Danish locale (, as decimal separator, . as thousands separator)47,50, as it inteprets the first dot wrongIn Database/Type/DecimalType.php the original code is:
public function marshal($value)
{
if ($value === null || $value === '') {
return null;
}
if (is_numeric($value)) {
return (float)$value;
}
if (is_string($value) && $this->_useLocaleParser) {
return $this->_parseValue($value);
}
if (is_array($value)) {
return 1;
}
return $value;
}
The first check with is_numeric() should be in my opinion exchanged and the $this->_useLocaleParser test should be first - so that Cake checks my locale-aware choices first (as I told Cake to do so by calling useLocaleParser() in bootstrap.php.
When I changed the order of tests - everything worked as it should: value of 47500 was displayed then as 47.500 and saved again correctly.
Please check the same paragraph in issue #10873. I would in general expect, that when I tell Cake to work with locale-aware values that it will respect my choice.
Checking for localized string before doing is_numeric() check when locale parser has been enabled does make sense.
@micdobro Would you like to make a PR with suggested change?
Pull request open now.
Most helpful comment
Checking for localized string before doing
is_numeric()check when locale parser has been enabled does make sense.