Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
44
rated 0 times [  46] [ 2]  / answers: 1 / hits: 68842  / 14 Years ago, mon, february 7, 2011, 12:00:00

in Javascript I can't seem to find a method to set negatives to zero?



-90 becomes 0

-45 becomes 0

0 becomes 0

90 becomes 90



Is there anything like that? I have just rounded numbers.


More From » math

 Answers
64

Just do something like



value = value < 0 ? 0 : value;


or



if (value < 0) value = 0;


or



value = Math.max(0, value);

[#93854] Saturday, February 5, 2011, 14 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
breap

Total Points: 606
Total Questions: 96
Total Answers: 108

Location: Djibouti
Member since Sun, Feb 27, 2022
2 Years ago
breap questions
Thu, Jun 24, 21, 00:00, 3 Years ago
Wed, Mar 18, 20, 00:00, 4 Years ago
Mon, Oct 7, 19, 00:00, 5 Years ago
;