Print this page

Why is the field of data type number storing more numbers in decimal places than defined?

Knowledge Article Number 000212661
Description
Define a custom number field, say, "Number."  Give it length = 3, and decimal places = 1. It might seem that this is done to restrict the precision of the field to two decimal places. However, on the UI level (on a standard edit page), if you try to type in, say, 237.631,  it'll round off 237.631 when you click "Save" and store it in the database as 237.6
 
But if you then set a value via API, say 237.631, it'll be stored in the database - and returned via API (e.g. SOQL query) - as 237.631.  
In fact , SFDC will let you store up to 24 decimal points via API, regardless of the decimal places provided in the field definition.  So you could save 237.123456789012345678901234.

This is completely working as designed and we kept the behavior so that it can be backward compatible.User-added image

Please note that the length and decimal places are only enforced when editing data via the standard web UI. Apex and API methods can actually save records with decimal places. This is true for standard and custom fields. Salesforce changes the display to match the definition, but they are stored in the database as inserted.

When the user sets the precision in custom fields in the Salesforce 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.

Reference Link:
https://www.salesforce.com/developer/docs/api/Content/primitive_data_types.htm


 




promote demote