Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ternary operator usage

Whats wrong with this seemingly straightforward code?

invoice.GST > gstValue ? invoice.GST -= gstValue : invoice.GST = 0;

VS complains
Only assignment, call, increment, decrement, and new object expressions can be used as a statement

like image 974
Null Head Avatar asked May 23 '26 14:05

Null Head


1 Answers

Try this:

invoice.GST = ((invoice.GST>gstValue)?(invoice.GST - gstValue):0);
like image 184
Chandu Avatar answered May 25 '26 05:05

Chandu