-3

Right now I have the following code:

if ($costOne <> $costTwo) {}

and I'd like to change this to

if ($costOne is not within the range of $costTwo - .0001 and $costTwo + .0001) {}

I've tried writing this a few different ways but I'm not doing something right.... can someone provide me the correct syntax to express this?

lordterrin
  • 165
  • 2
  • 2
  • 10

2 Answers2

3

You basically had it:

((($costTwo - 0.0001) <= $costOne) && ($costOne <= ($costTwo + 0.0001)))

Or, alternatively

(abs($costOne - $costTwo) <= 0.0001)
Marc B
  • 356,200
  • 43
  • 426
  • 500
0

You can do it like below:

$lowerbounds = $costOne - .0001;
$higherbounds = $costOne + .0001;
if($costOne < $lowerbounds || $costOne > $higherbounds){ ....
Djave
  • 8,595
  • 8
  • 70
  • 124