ChadNomad Posted December 23, 2007 Share Posted December 23, 2007 How do I know if a number is positive or negative? For example if the integer is 10 I want to + 10 and if it's -16 I want to - 16... Hope that makes sense! Quote Link to comment Share on other sites More sharing options...
corbin Posted December 23, 2007 Share Posted December 23, 2007 Luckily, the way positive and negative numbers works, you can do the following: $a + $b Let's say a is 10 and b is 9, that will yield 19.... Let's say b is -9.... 10+-9 That would be 1 ;p. Quote Link to comment Share on other sites More sharing options...
thebadbad Posted December 23, 2007 Share Posted December 23, 2007 For your particular example, you could just multiply the number with 2! <?php $num *= 2; echo $num; //outputs 20 when $num = 10, and -32 when $num = -16. ?> If that's not what you needed, let me know Quote Link to comment Share on other sites More sharing options...
ChadNomad Posted December 23, 2007 Author Share Posted December 23, 2007 Luckily, the way positive and negative numbers works, you can do the following: $a + $b Let's say a is 10 and b is 9, that will yield 19.... Let's say b is -9.... 10+-9 That would be 1 ;p. Yeah I just noticed that! Thanks Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.