$price = "20.00"; $price = preg_replace('/\.0+$/', '', $price); echo $price."\n"; //结果: 20 $price = "20.60"; $price = preg_replace('/\.0+$/', '', $price); echo $price."\n"; //结果: 20.60
php怎样把类似价格“20.00元”里的.00替换掉
$price = "20.00"; $price = preg_replace('/\.0+$/', '', $price); echo $price."\n"; //结果: 20 $price = "20.60"; $price = preg_replace('/\.0+$/', '', $price); echo $price."\n"; //结果: 20.60