Fixes #10488: Fixed incorrect behavior of yii\validation\NumberValidator when used with locales where decimal separator is comma

This commit is contained in:
Alexander Makarov
2016-12-02 00:04:30 +03:00
parent dd94ead358
commit b17dfa03a2
3 changed files with 16 additions and 11 deletions

View File

@ -120,17 +120,21 @@ class NumberValidator extends Validator
/**
* Returns string represenation of number value with replaced commas to dots, if decimal point
* of current locale is comma
* @param $value
* @param int|float|string $value
* @return string
*/
private function getStringValue($value)
{
$value = (string)$value;
$localeInfo = localeconv();
if (isset($localeInfo['decimal_point']) && $localeInfo['decimal_point'] ==',') {
return str_replace(',', '.', "$value");
} else {
return "$value";
$decimalPointSeparator = isset($localeInfo['decimal_point']) ? $localeInfo['decimal_point'] : null;
if ($decimalPointSeparator !== null && $decimalPointSeparator !== '.') {
$value = str_replace($decimalPointSeparator, '.', $value);
}
return $value;
}
/**