那是因为你正在使用$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
你期待什么?你的地板是''''。 –