Index: branches/unlabeled/unlabeled-1.1.2/core/kernel/utility/formatters/formatter.php =================================================================== diff -u -r4950 -r6508 --- branches/unlabeled/unlabeled-1.1.2/core/kernel/utility/formatters/formatter.php (.../formatter.php) (revision 4950) +++ branches/unlabeled/unlabeled-1.1.2/core/kernel/utility/formatters/formatter.php (.../formatter.php) (revision 6508) @@ -20,6 +20,17 @@ $type_ok = preg_match('#int|integer|double|float|real|numeric|string#', $field_type); if($field_type == 'string') return $value; + static $comma = null; + static $thousands = null; + if (is_null($comma) || is_null($thousands)) { + $lang =& $this->Application->recallObject('lang.current'); + $comma = $lang->GetDBField('DecimalPoint'); + $thousands = $lang->GetDBField('ThousandSep'); + } + + $value = str_replace($thousands, '', $value); + $value = str_replace($comma, '.', $value); + if ($value != '' && $type_ok) { $ret = is_numeric($value); @@ -43,10 +54,26 @@ $options = $object->GetFieldOptions($field_name); if ( isset($format) ) $options['format'] = $format; $tc_value = $this->TypeCast($value,$options); - if( ($tc_value === false) || ($tc_value != $value) ) return $value; // for leaving badly formatted date on the form + if( ($tc_value === false) || ("$tc_value" != "$value") ) return $value; // for leaving badly formatted date on the form - if (isset($options['format'])) return sprintf($options['format'], $tc_value); + if (isset($options['format'])) { + $tc_value = sprintf($options['format'], $tc_value); + } + if (preg_match('#int|integer|double|float|real|numeric#', $options['type'])) { + static $comma = null; + static $thousands = null; + if (is_null($comma) || is_null($thousands)) { + $lang =& $this->Application->recallObject('lang.current'); + $comma = $lang->GetDBField('DecimalPoint'); + $thousands = $lang->GetDBField('ThousandSep'); + } + + //counting decimal places after formatting with sprintf (if any), otherwise - 0 + $dec_places = preg_match('/[\.,]+/', $tc_value) ? strlen(preg_replace('/^.*[\.,]+/', '', $tc_value)) : 0; + return number_format($tc_value, $dec_places, $comma, $thousands); + } + return $tc_value; }