function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion

Decimal Places

Hi all,


When you create a field of type number, you are allowed to enter a number of digits before and after the decimal.  My understanding was that if you entered  a value with too many digits before or after the decimal place, you would get an error on insert/update.  However, that is not the case.



MyObject__c mo = new MyObject__c();
mo.Name = 'Testing rounding';
mo.Temporary__c = 123.4567890; //This field defined as Number(10,2)
insert mo;
System.debug('val = ' + mo.Temporary__c);



I would expect one of two outcomes from the above code:


1) Exception when I try to insert.


2) Truncate or round the number accordingly.


However, instead the debug statement prints out:



14:42:44.063|USER_DEBUG|[6]|DEBUG|val = 123.4567890



So...what does limiting the number of digits before/after the decimal place even do?  Do I really have to manually chop this number off at 2 decimal places every time I want to use it?




I found this in the documentation when researching a similiar issue:


When the user sets the precision in custom fields in the application, it displays the precision set by the user, even if the user enters a more precise value than defined for those fields. However, when you set the precision in custom fields using the API, no rounding occurs when the user retrieves the number field.