I encountered the same problem using SugarCRM CE 5.0.0e. Values entered (or already present) in custom decimal / float fields got altered in strange ways upon saving. E.g. 0.45 turned to 45.00, 12.3 became 123.00, and a tax quote of 25.00 percent would end up as 2,500.00. So I had to dive into the PHP code to nail down this problem...
For this issue to occur it seem's you have to a) use custom floating point fields and b) change the number separators, so the thousands separator is '.' - this is common in Europe in conjunction with ',' for the decimal separator. The problem arises because values entered get parsed / converted twice. The second alteration is wrong and leads to incorrect data stored in the database fields - to me this clearly looks like a bug in SugarCRM.
Values entered first get processed within the save() function of data/SugarBean.php (line #1140). The function uses PHP Code:
$this->unformat_all_fields();
which in turn calls unformat_number. Numeric input ends up in 'ANSI C' format this way - say e.g. "16,0" entered in 'European format' will end up as "16.0". However, examining the code that follows reveals that custom fields get treated as special, since they handle their save seperately. Line #1330 calls the save() function of modules/DynamicFields/DynamicField.php (declared at line #214) to achieve this.
But - lo and behold - guess what this function does with the value that unformat_all_fields has worked on?
PHP Code:
if($field['type'] == 'int' || $field['type']== 'float'){
if (!empty($this->bean->$name)) {
$this->bean->$name = unTranslateNum($this->bean->$name);
}
It uses unTranslateNum() on numeric fields and thus causes havoc. Looking at unTranslateNum() (declared in include/utils.php at line #1477) quickly reveals that this function again tries to convert the decimal separator and strips the thousands separator from the input string. Given this is '.', the already processed "16.0" turns to "160" - which is clearly not the intended value to be stored in the database.

My (quick and dirty) workaround for this problem is a simple 'sanity check' to see if unformat_all_fields already worked on the fields - since the function sets an appropriate flag for the bean. So changing the above part of DynamicField.php to
PHP Code:
if($field['type'] == 'int' || $field['type']== 'float'){
if (!$this->bean->unformated_numbers) {
if (!empty($this->bean->$name)) {
$this->bean->$name = unTranslateNum($this->bean->$name);
}
}
did the job for me.
Hope this helps.
Regards, bnortmann
[EDIT] typos...
Bookmarks