$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
Maison >développement back-end >tutoriel php > php怎样把相仿价格“20.00元”里的.00替换掉
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