Understand user number preference when importing and exporting floats

This commit is contained in:
Nathan Gray 2013-09-04 15:15:55 +00:00
parent addb422abe
commit 580d8c15a3
2 changed files with 14 additions and 2 deletions

View File

@ -391,9 +391,13 @@ class importexport_export_csv implements importexport_iface_export_record
if (empty($dec_separator)) $dec_separator = '.';
$thousands_separator = $GLOBALS['egw_info']['user']['preferences']['common']['number_format'][1];
}
if($record->name && (string)$record->$name != '')
if($record->$name && (string)$record->$name != '')
{
$record->name = number_format(str_replace(' ','',$record->name), 2,
if(!is_numeric($record->$name))
{
$record->$name = floatval(str_replace($dec_separator, '.', preg_replace('/[^\d'.preg_quote($dec_separator).']/', '', $record->$name)));
}
$record->$name = number_format(str_replace(' ','',$record->$name), 2,
$dec_separator,$thousands_separator
);
}

View File

@ -465,6 +465,14 @@ class importexport_import_csv implements importexport_iface_import_record { //,
$record[$name] = null;
}
}
foreach((array)$fields['float'] as $name)
{
if($record[$name] != null && $record[$name] != '') {
$dec_point = $GLOBALS['egw_info']['user']['preferences']['common']['number_format'][0];
if (empty($dec_point)) $dec_point = '.';
$record[$name] = floatval(str_replace($dec_point, '.', preg_replace('/[^\d'.preg_quote($dec_point).']/', '', $record[$name])));
}
}
// Some custom methods for conversion
foreach((array)$methods as $name => $method) {