<?php $tests = ['1.2', '1.0', '2.11']; foreach ($tests as $yearWithDecimal) { $years = floor($yearWithDecimal); $months = ($yearWithDecimal - $years) * 12; $totalMonths = ($years * 12) + $months; echo $totalMonths.PHP_EOL; // Output is 14.4 }
You have javascript disabled. You will not be able to edit any code.