on 19/7/06
Perhaps this will be useful for others.
I needed to be able to convert decimal number to and from the 'local' format. By adding the below methods to my app_model, it is possible to silently convert decimal numbers as they come out of the database to be local format, and vice versa to save. In the code below it is converting numbers of the format 999.999,99 to be 999999.99 - which otherwise would be saved by MySql as 999.99 as the rest of the number is ignored.
<?phpclass AppModel extendsModel{// Cheat for UTF-8function __construct(){parent::__construct();$this->execute("Set NAMES 'UTF8'");}function afterFind($results){foreach($results as $id=>$objectResult){foreach ($objectResult as $class=>$fields){if ($this->name==$class){$classObject = $this;}else{$classObject = new $class;}foreach($classObject->_tableInfo->value as $fieldDetails){$fieldName = $fieldDetails['name'];$fieldType = $fieldDetails['type'];if ($fieldType == "float"){if (isset($results[$id][$class][$fieldName])){$results[$id][$class][$fieldName] = number_format($results[$id][$class][$fieldName], 2, ',', '.');}}}}}return $results;}functionbeforeSave(){foreach ($this->data as $class=>$fields){if($this->name==$class){$classObject = $this;}else{$classObject = new $class;}foreach($classObject->_tableInfo->value as $fieldDetails){$fieldName = $fieldDetails['name'];$fieldType = $fieldDetails['type'];if ($fieldType == "float"){if(isset($this->data[$class][$fieldName])){$this->data[$class][$fieldName] = str_replace(array(".", ","), array("", "."), $this->data[$class][$fieldName]);}}}}return true;}}?>










