What are some best practices for converting decimal hours to hours and minutes in PHP?

When converting decimal hours to hours and minutes in PHP, you can use the floor() function to get the whole number of hours and then multiply the decimal part by 60 to get the minutes. You can then format the result as desired.

function convertDecimalToHoursMinutes($decimalHours) {
    $hours = floor($decimalHours);
    $minutes = ($decimalHours - $hours) * 60;
    
    return $hours . ' hours ' . $minutes . ' minutes';
}

// Example of converting 3.75 decimal hours to hours and minutes
echo convertDecimalToHoursMinutes(3.75); // Output: 3 hours 45 minutes