Loading

Salesforce Number Field Stores More Decimal Places Than Defined When Set via API or Apex

Veröffentlichungsdatum: May 1, 2026
Beschreibung
When you define a custom Number field in Salesforce — for example, with a length of 3 and decimal places of 1 — it might appear that this restricts the field to storing only one decimal place. However, the behavior differs depending on how the value is set.

For example, if you define a Number field with length = 3 and decimal places = 1, and a user enters 237.631 in the standard UI edit page, Salesforce will display 237.6 after saving (rounded to 1 decimal place). However, the value 237.631 is stored in the database. If you then set the same value via API (for example, via a SOQL query or Apex), 237.631 is both stored in the database and returned by the API without rounding.
 
Lösung

This is expected behavior and is maintained for backward compatibility in Salesforce.

UI Behavior (Standard Web Interface)

The length and decimal places defined on a Number field are only enforced when editing data via the standard Salesforce web UI. When a user enters a value more precise than the field definition, Salesforce rounds and displays the value according to the field definition — but stores the full precision value in the database.

API and Apex Behavior

Apex and API methods can save records with decimal places beyond the field definition. Salesforce changes the display to match the field definition, but the full precision value is stored in the database as inserted. When you retrieve the value via API, no rounding occurs.

Lightning Experience vs. Salesforce Classic

In Lightning Experience, custom objects store more decimal places than the default number set for the field. For example, if you enter 90.678 on a field that accepts 2 decimal places, the record form displays 90.68, but inline edit shows the original 90.678, and 90.678 is stored in the database.
In Salesforce Classic, the value 90.678 on a 2-decimal-place field is saved as 90.68 in the database.

Java Double Type Precision Limit

The precision of Number values managed through the UI or SObject API is limited by the precision of the Java Double type. For example, entering 49.999999999999972 into a Number field on the UI will result in 49.99999999999997 being stored in the database.



Reference Link: Primitive Data Types

Nummer des Knowledge-Artikels

000387302

 
Laden
Salesforce Help | Article