Just a quick question, can this sum be written in one short line:
a = (b / c) * 100;
if (a < 0) a = 0;
Apart from the obvious way which is equally long:
if ((b / c) * 100) > 0) a = (b / c) * 100; else a = 0;
EDIT: And the ternary version of this is no different, I didn't think I needed to mention.
Maybe there isn't a short, neat and clever way to write this but I was just hoping there was since it always seems unnecessary to have that extra line underneath.
You could take Math.max
along with zero.
a = Math.max(b * 100 / c, 0);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With