simple:
Result = (decimal)((test1 == null || test1 == 0) ? 0 : ((test2 - (test1 ?? 0)) / test1));
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Give the example below, I'm getting a Divide by Zero exception error. Can you please advise me how to set the Result value to zero if the data in field test1 is zero?
I can't use at "try catch" of "if statement" because the code that is doing the calculation is inside of a linq join condition. Thanks for your help.
decimal? Result = 0;
decimal? test1 = 0;
decimal? test2 = 57;
Result = (decimal)(test1 == null ? 0 : ((test2 - (test1 ?? 0)) / test1));
simple:
Result = (decimal)((test1 == null || test1 == 0) ? 0 : ((test2 - (test1 ?? 0)) / test1));
Hi Bruce, thanks for your response. If test2 is null, I get this error: Nullable object must have a value.