It appears that you have one variable that stores an amount of minutes, $cat['prepration_time']
in your case. To output the minutes as decimal hours all you really need to do is to divide the number of minutes by 60, that's the number of minutes in one hour. In your case that would be
echo $cat['preparation_time'] / 60 . ' hours';
To avoid awkward results like 1.33333333333 hours
, you can additionally wrap the calculation in round, where the second parameter of round
is the precision, i.e. the number of digits behind the dot.
$minutes = 77;
echo round($minutes / 60, 2) . ' hours'; // 1.28 hours
Be aware however that this format is badly readable and prone to misunderstanding. Does 1.30 hours
mean 1 hour and 30 minutes
or rather 1 hour and 18 minutes
? And while you might be able to convert 1.30 hours
in your head, you will surely need a calculator for 1.283 hours
. I would recommend to use a commonly understood and unambiguous format, like for example 1 hour and 32 minutes
, or 1:32 hours
.