我用下面的代碼來實現這一目標:將包含月數的變量轉換爲X年,X.5個月格式?
$total_months = 59;
$years = (int)($total_months/12);
$months = $total_months % 12;
輸出爲4年11個月...
如果輸入的是:
$total_months = 59.5;
$years = (int)($total_months/12);
$months = $total_months % 12;
我需要的輸出4年,11.5個月...
有人會幫我拿出結果嗎?
在此先感謝。
'$個月= $ total_months - ($年* 12);'? – Aquillo
多年來,你可以做的地板($ total_months/12) – MKroeders