mirror of
https://github.com/e107inc/e107.git
synced 2025-08-03 13:17:24 +02:00
fixed float numbers troubles (caused by system localization)
This commit is contained in:
@@ -1603,15 +1603,19 @@ class e_model extends e_object
|
|||||||
* @return integer|float
|
* @return integer|float
|
||||||
*/
|
*/
|
||||||
public function toNumber($value)
|
public function toNumber($value)
|
||||||
{
|
|
||||||
if(!is_numeric($value))
|
|
||||||
{
|
{
|
||||||
$larr = localeconv();
|
$larr = localeconv();
|
||||||
$search = array($larr['decimal_point'], $larr['mon_decimal_point'], $larr['thousands_sep'], $larr['mon_thousands_sep'], $larr['currency_symbol'], $larr['int_curr_symbol']);
|
$search = array(
|
||||||
|
$larr['decimal_point'],
|
||||||
|
$larr['mon_decimal_point'],
|
||||||
|
$larr['thousands_sep'],
|
||||||
|
$larr['mon_thousands_sep'],
|
||||||
|
$larr['currency_symbol'],
|
||||||
|
$larr['int_curr_symbol']
|
||||||
|
);
|
||||||
$replace = array('.', '.', '', '', '', '');
|
$replace = array('.', '.', '', '', '', '');
|
||||||
$value = str_replace($search, $replace, $value);
|
|
||||||
}
|
return str_replace($search, $replace, $value);
|
||||||
return (0 + $value);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -653,7 +653,12 @@ class e_db_mysql
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case 'float':
|
case 'float':
|
||||||
return (float) $fieldValue;
|
// fix - convert localized float numbers
|
||||||
|
$larr = localeconv();
|
||||||
|
$search = array($larr['decimal_point'], $larr['mon_decimal_point'], $larr['thousands_sep'], $larr['mon_thousands_sep'], $larr['currency_symbol'], $larr['int_curr_symbol']);
|
||||||
|
$replace = array('.', '.', '', '', '', '');
|
||||||
|
|
||||||
|
return str_replace($search, $replace, floatval($fieldValue));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'null':
|
case 'null':
|
||||||
|
@@ -440,7 +440,7 @@ class e_validator
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case 'float':
|
case 'float':
|
||||||
$value = floatval($value);
|
$value = 0.00;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'array':
|
case 'array':
|
||||||
@@ -570,6 +570,7 @@ class e_validator
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case 'float':
|
case 'float':
|
||||||
|
$value = $this->toNumber($value);
|
||||||
if(!is_numeric($value))
|
if(!is_numeric($value))
|
||||||
{
|
{
|
||||||
$this->addValidateResult($name, self::ERR_FLOAT_EXPECTED);
|
$this->addValidateResult($name, self::ERR_FLOAT_EXPECTED);
|
||||||
@@ -586,7 +587,7 @@ class e_validator
|
|||||||
$this->addValidateResult($name, self::ERR_TOO_HIGH);
|
$this->addValidateResult($name, self::ERR_TOO_HIGH);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$this->addValidData($name, (float) $value);
|
$this->addValidData($name, $value);
|
||||||
return true;
|
return true;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@@ -721,6 +722,22 @@ class e_validator
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function toNumber($value)
|
||||||
|
{
|
||||||
|
$larr = localeconv();
|
||||||
|
$search = array(
|
||||||
|
$larr['decimal_point'],
|
||||||
|
$larr['mon_decimal_point'],
|
||||||
|
$larr['thousands_sep'],
|
||||||
|
$larr['mon_thousands_sep'],
|
||||||
|
$larr['currency_symbol'],
|
||||||
|
$larr['int_curr_symbol']
|
||||||
|
);
|
||||||
|
$replace = array('.', '.', '', '', '', '');
|
||||||
|
|
||||||
|
return str_replace($search, $replace, $value);
|
||||||
|
}
|
||||||
|
|
||||||
protected function parseMinMax($string)
|
protected function parseMinMax($string)
|
||||||
{
|
{
|
||||||
return explode(':', $this->_convertConditionBC($string), 2);
|
return explode(':', $this->_convertConditionBC($string), 2);
|
||||||
|
Reference in New Issue
Block a user