5
I have this code, and I’ve been searching for a way to simplify it using a ternary operator, but I’m not getting it because it says I can’t use decimal string:
decimal per;
if (nud_qtPedida.Value != 0)
per = nud_qtFornecida.Value * 100 / nud_qtPedida.Value;
else
per = 0;
txt_percentagem.Text = per.ToString();
Just be careful not to abuse the use of ternary operators, as they in some circumstances make it difficult to read and maintain the code. I see no problem in the question code that needs to be placed on a
If
ternary.– Richard Dias