This extension method should help. It cancels the operation and checks if the original arguments can be correctly calculated from the result. If this is not so, then the operation caused a loss of accuracy.
public static decimal Add(this decimal a, decimal b) { var result = a + b; if (result - a != b || result - b != a) throw new InvalidOperationException("Precision loss!"); return result; }
Working example: https://dotnetfiddle.net/vx6UYY
If you want to use regular operators like + , etc., you have to go with Philipp Schmid solution and implement the operators according to your decimal type.
source share