What are the potential pitfalls of converting time to decimal in PHP, as seen in the provided code snippet?

Converting time to decimal in PHP can lead to inaccuracies due to rounding errors or the loss of precision. To avoid these pitfalls, it is recommended to use PHP's built-in DateTime class to handle time calculations and conversions accurately.

// Fix: Convert time to decimal using DateTime class

$startTime = new DateTime('08:30:00');
$endTime = new DateTime('10:45:00');

$interval = $startTime->diff($endTime);
$totalHours = $interval->h + $interval->i / 60;

echo $totalHours; // Output: 2.25