SugarCRM Decimal Field

Hi All,

I have created the decimal type field using vardef where the length is 18 and precision is 15 which is also same in MySQL but when i try to update the field value up to 15 decimal like 34.1234567899876489, it is storing as rounded value up to 11 digit like 34.12345678999

Can someone let me know what exactly i need to do to achieve this.

Thanks 

  • Hi ,

    This was an interesting problem to solve and the problem lies with PHP precision settings (this is a bit different from MySQL).

    precision - The number of significant digits displayed in floating point numbers. -1 means that an enhanced algorithm for rounding such numbers will be used.

    The default value for precision is 14, so your number gets trimmed to 34.12345678999 (with 14 digits)

    In order to support more finer precision, you can increase the value in your php.ini to a larger number - which is 18 in your scenario.

    ; The number of significant digits displayed in floating point numbers.
    ; http://php.net/precision
    precision = 18

     

  • ok thanks Neeraja. but i want to know is there any other restriction of field size also like we can store upto 28 digit only something like this including integer and fraction.

  • I don't think there is any other restriction, but please be aware of PHP floating point warning in the PHP Docs:

    https://www.php.net/manual/en/language.types.float.php