I have a Formula field which does simple subtraction between two other fields.
Field X - Formula (return type Number, 2 decimal places).
Field Y - Currency(16, 2)
The formula field simply does :
X - Y. It is Currency return type,
I'm seeing differences in math when replicating what the Formula field does (simple subtraction in Apex).
When X and Y are both
-0.01, the difference should be
Formula Field computes to :
Apex Subtraction computes to:
The above values were printed using
I know Currency's round "half-even" by default, but even when using
System.RoundingMode.HALF_EVEN on both X and Y, the Apex calculation is still rightfully
Any help is appreciated!
// obj.X - Formula (Return type Number, 2 decimal places.) // obj.Y - Currency (16,2) 16 length, 2 decimal places. // obj.Z - Formula (Currency, 2 decimal places) - `X - Y` System.debug(obj.X); //X prints -0.01 System.debug(obj.Y); //Y prints -0.01 System.debug('MANUAL MATH'); System.debug(obj.X - obj.Y); //Apex math prints 0.00 System.debug('Formula field'); System.debug(obj.Z); //Z prints 0.01