Home > Backend Development > PHP Tutorial > php怎么去除小数点后面的0

php怎么去除小数点后面的0

WBOY
Release: 2016-06-13 10:09:10
Original
1576 people have browsed it

php如何去除小数点后面的0


php如何去除小数点后面的0


现有小数2002.001 用PHP如何将小数点后面1前面的零去掉。即:2002.1

------解决方案--------------------
啥规律?
------解决方案--------------------
去掉了,值也变了
------解决方案--------------------

PHP code
$num=explode(".","2002.001");$num[1]=str_replace(0,"",$num[1]);echo implode(".",$num);<br><font color="#e78608">------解决方案--------------------</font><br>作为字符来处理,可<br>
Copy after login
PHP code
$str    = "2002.001.002.12.05";echo    preg_replace('/(?<font color="#e78608">------解决方案--------------------</font><br>去掉0,不就把数字值改变了,数字还有效吗<br><font color="#e78608">------解决方案--------------------</font><br>用intval函数就可以了<br><br>echo intval(7533.725548);<br><br>echo intval(7533.225548);<br><font color="#e78608">------解决方案--------------------</font><br>你的说清楚的需求!也许你是想最后的结果是表示的年月【2012.2】<br><br>但是你在存数据的时候,莫名其妙的2前面有0,right???<br><font color="#e78608">------解决方案--------------------</font><br>正则匹配<div class="clear">
                 
              
              
        
            </div>
Copy after login
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template