What formula to calculate the following:
Given:
$width = 300; $height = 500.5; $scale = 16/9; I need to pick the integers $newWidth and $newHeight to match the conditions
$newWidth / $newHeight == $scale && $newWidth >= $width && $newHeight >= $height Explain in words or a formula, how to count it?
There is a sketch:
function aloe($width, $height, $scale){ if ($width / $height > $scale) { $newWidth = $width; $newHeight = round($width / $scale); } else { $newHeight = $height; $newWidth = round($height * $scale); } return $newWidth / $newHeight; } But for some reason, the result has an error:
echo ( aloe(300, 500, 1.55) === aloe(233, 123, 1.55) ? "Все ок" : "Погрешность!"); //Погрешность!
roundin your calculations, so a mismatch is quite expected. - VladD