1
0
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:
secretr
2011-01-04 12:10:47 +00:00
parent f7ec4cc5e5
commit 2945d24e0c
3 changed files with 37 additions and 11 deletions

View File

@@ -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);
} }
/** /**

View File

@@ -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':

View File

@@ -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);