-1

how would i stop the below returning a value less than 0. I want anything less than 0 to show as 0. Any help appreciated.

$("#spanrPower_CO2").text (Math.round(-data[0] * 16.8) * 100 / 100);
BjH
  • 33
  • 2

2 Answers2

2

data[0] > 0 ? 0 : -Math.round(16.8 * data[0]); is probably clearer.

Note that unless you're approaching floating point infinity, * 100 / 100 is a no-op.

Bathsheba
  • 227,678
  • 33
  • 352
  • 470
0
(Math.max(0, -data[0] * 16.8).toFixed(0));
BjH
  • 33
  • 2