<?php
function getGridStepForValue(float $c, int $minCountLines): float
{
$config = [50, 20, 15, 10];
$n = ceil($c);
$length = \strlen((string)$n);
while ($length) {
foreach ($config as $singleDivisor) {
$nDivisor = (float)str_pad((string)$singleDivisor, $length, '0');
if ($n - ($nDivisor * $minCountLines) > 0) {
return $nDivisor;
}
}
$length--;
}
return getGridStepForValue($c * 10, $minCountLines) / 10;
}
var_dump(
getGridStepForValue(1, 4),
getGridStepForValue(1, 5)
);
preferences:
53.94 ms | 402 KiB | 5 Q