mirror of
https://github.com/yiisoft/yii2.git
synced 2025-11-03 05:48:11 +08:00
Fixes #10488: Fixed incorrect behavior of yii\validation\NumberValidator when used with locales where decimal separator is comma
This commit is contained in:
@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user