那是因爲你正在使用$25.00
作爲輸入和$
使得PHP認爲你想圓一個字符串 - PHP將圓一個(非數字)串0
floor
=向下。
ceil
=取整。
round
=他們教你文法學校
但如果你有字符串中$
無那些將工作同樣的過程。我建議你做一些類似'$' . round(str_replace('$', '', $price) * 100)/100
的事情。 (乘法和除法使它四捨五入到最接近的一分錢(而不是美元),str_replace
使它處理一個數字值,然後加上$
。如果你真的很喜歡,那麼按照下面)
$dollar = '$' . round(str_replace('$', '', $price) * 100)/100;
// the following makes sure that there are two places to the right of the decimal
$pieces = explode('.', $dollar);
if(isset($pieces[1]) && strlen($pieces[1]) == 1)
{
$pieces[1].='0';
$dollar = implode('.', $pieces);
}
// if you like, you can also make it so that if !pieces[1] add the pennies in
你期待什麼?你的地板是''''。 –