Loading

Salesforce Automatically Rounds Number, Currency, and Percent Values That Exceed the "Decimal Places" Setting

Veröffentlichungsdatum: Dec 16, 2025
Beschreibung

In Salesforce, entering a value with more decimal places than the field definition allows in a Number, Currency, or Percent field causes the system to round and save the value by default. This article explains how to prevent input values from being modified unintentionally by using the MOD function in a Validation Rule. The Validation Rule displays an error message when an input exceeds the specified number of decimal places.

Lösung

This article explains how the Validation Rule formula logic works to prevent Salesforce from silently rounding a Number, Currency, or Percent field value that exceeds its configured "Decimal Places" setting.

How the Validation Rule Logic Works

The logic used in the Validation Rule formula is to "shift the decimal point to the right (by multiplying), and if a decimal value still remains (the remainder when divided by 1 is not 0), trigger an error."

Example: Limiting Input to 2 Decimal Places

To evaluate the value, multiply the number by 100 to shift the decimal point two places to the right.

  1. Valid Case (Saved successfully)
    Input Value: 123.45
    Shift right by 2 (x100): 12345
    Result: Since no decimal remains, the value is saved.
  2. Error Case
    Input Value: 123.456
    Shift right by 2 (x100): 12345.6
    Result: Since a fractional part (".6") remains, the Validation Rule triggers an error.

Formula Configuration for Number and Currency Fields

Set the number of zeros for multiplication according to the number of decimal places you want to limit.

Example: To limit to "2 decimal places":

MOD( FieldName__c * 100, 1 ) <> 0

Note: Replace FieldName__c with the API Name of your Number or Currency field. Because we want to check up to the 2nd decimal place, we multiply by 100 (two zeros) to shift the decimal point.

Formula Configuration for Percent Fields

Percent fields are stored in the database as a value divided by 100 (e.g., 10% is stored as 0.1). Therefore, in addition to the visible decimal places on the screen, you must account for the digits used for the percentage conversion.

Example: To limit to "2 decimal places" as displayed on the screen:

MOD( FieldName__c * 10000, 1 ) <> 0

Note: Replace FieldName__c with the API Name of your Percent field. You need to shift by a total of 4 digits: the "2 decimal places" visible on the screen plus the "invisible 2 digits" (due to the /100 storage specification). Therefore, multiply by 10,000 (four zeros).

Nummer des Knowledge-Artikels

005132292

 
Laden
Salesforce Help | Article