Alex Rivera | Logout

Detecting negative numbers

Asked 2011-05-26T07:44:05.167
72

I was wondering if there is any way to detect if a number is negative in PHP?

I have the following code:

$profitloss = $result->date_sold_price - $result->date_bought_price;

I need to find out if $profitloss is negative and if it is, I need to echo out that it is.

Edit
Report

1 Answer

22
if(x < 0)
if(abs(x) != x)
if(substr(strval(x), 0, 1) == "-")
answered 2011-05-26T07:52:22.970

Your Answer