Home >Backend Development >PHP Tutorial > php怎样把相仿价格“20.00元”里的.00替换掉

php怎样把相仿价格“20.00元”里的.00替换掉

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-06-13 12:30:171012browse

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
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn