我得到了以下的問題:我有像PHP:計算與仙
2,50
1
2,99
值現在我想將它們分成2個部分是這樣的:
2 and 50
1 and 00
2 and 99
$euro = explode('.', $item->price)[0];
if(array_key_exists(1, explode('.', $item->price))) {
$cent = explode('.', $item->price)[1];
}
else
{
$cent = "00";
}
這不我應該這樣做的方式,我猜;-)
還有一個問題:現在我得到以下值:
2 and 5
1 and 00
2 and 99
但應
2 and 50
1 and 00
2 and 99
爲什麼你想這樣做?得到50,而不是5,你需要使用strval(),以便它被轉換爲字符串,number_format()會爲你工作嗎?或money_format()? –
添加0使50你可以使用'str_pad($ cent,2,0)' – Neat
我需要這樣做,因爲webdesigner增加了一個特殊的類到cent-values ;-) – MyFault