The Arcive of Official vBulletin Modifications Site.It is not a VB3 engine, just a parsed copy! |
|
#1
|
||||
|
||||
[php] Using the abs() function ?
Doing some calculations that may wary depending on the user, and
content calculated ofcourse.. But ewentually its bound to happen i will hit values below 0 and using integers as whole numbers no decimals one calc could be as simple as $result=$contentA-$ContentB But i feel like i dont have control over it, it might end up being 100 - 10 and will result in -90 So ive found the php manual and read about abs(); But got worried reading all the comments below http://php.net/manual/en/function.abs.php ----------------- What i want, is if the case is that $result ends up as a negative value i just want to turn it positive. so in the case above the -90 would be 90. was thinking doing something like this PHP Code:
|
#2
|
|||
|
|||
not sure about abs function but you can also use a simple math to achieve that
PHP Code:
if 0, it will become 0 with abs, apparently 0 turns into 1 |
#3
|
||||
|
||||
Thank you winstone.
|
#4
|
||||
|
||||
PHP Code:
|
#5
|
||||
|
||||
Thank you it works, went back to abs
cause the math solution came up with some strange numbers.. |
#6
|
||||
|
||||
Quote:
PHP Code:
|
#7
|
|||
|
|||
Wouldn't the non abs method just be multiply by -1 if the value is less than 0?
PHP Code:
|
#8
|
||||
|
||||
Quote:
-500 * 1 = -500 still.. try it on your calculator in your OS. |
#9
|
|||
|
|||
Quote:
-500 * -1 = 500. Hence the if statement to make sure the result is less than 1. If result is positive then it wouldn't need to do anything to it. Though really looking back at it what I put was slightly wrong. It should be if ($result < 0) rather than <= 0 as there's no point multiplying 0 by -1. |
#10
|
||||
|
||||
right got it year that would work..
|
|
|
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
More Information | |
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|