[SalesForce] How to run an integer validation rule against a Number(x, 0) field

I see in the Number documentation that Salesforce does some rounding, but I'm observing truncation. In the Number Validation Rules from Salesforce there is a Number Must Be an Integer validation rule that specifies that the following can be used to validate that a field is an integer.

FLOOR( My_Integer__c) <> My_Integer__c

I have a field defined as Number(4,0) and I have that validation rule, but the rule is not firing when a value that is not an integer is entered. Instead it truncates the decimal part.

For example, if I enter in 1.75 it will silently change the value to a 1, without a validation failure.

I would rather have the error message displayed to the user than silently changing the number that was input, but I don't want to change the actual data type from Number(4,0).

For good measure, here's the validation rule:
Validation Rule for Integer

I did see https://salesforce.stackexchange.com/a/3455/154 which seems closely related; however, Java's Integer.parseInt (at least in Java 1.6.0_25) throws a NumberFormatException for non Integer values (e.g, "1.75").

I am open to other possibilities, but would rather not have to code something.

The field is in a managed package and I cannot change its definition from Number(4,0).

Best Answer

If you defined the field with zero decimal places then you do not need that validation rule; you have defined the field to be an integer. I am surprised that Salesforce just silently truncates the input, though, as I would have expected a system error message.

Related Topic