0

I'm using this code:

if (($height/$width) > 0.5 && ($height/$width) < 0.8) {
  // do stuff
}

For a particular image, $height/$width evaluates to 0.66543438077634 (1080/1623). And yet this appears to be evaluating as false. Can anyone suggest why?

1
  • Have you tried to parse float the height and width before the comparison? Somehing like: if ((floatval($height)/floatval($width)) > 0.5) ... Commented Nov 15, 2013 at 9:33

2 Answers 2

2

Propably You have some problem someware else because this code works fine:

<?
    $height = 1080;
    $width = 1623;
    if (($height/$width) > 0.5 && ($height/$width) < 0.8) {
        echo 'IT WORKS';
    }
    var_dump(($height/$width));
?>

SEE WORKING CODE!

Sign up to request clarification or add additional context in comments.

1 Comment

Yes, this was a different issue... Wasn't testing well enough. Sorry!
0

Try it like

$div = (float)($height/$width);
if ( $div > 0.5 && $div < 0.8) {
  // do stuff
}

Or you can use

$div = (float)($height)/(float)($width);

1 Comment

No dice... Still false.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.