Home  >  Article  >  Backend Development  >  php取一位小数

php取一位小数

WBOY
WBOYOriginal
2016-06-13 10:34:221182browse

php取一位小数,在线等
$str = 35.5454;

现想取 35.5
怎么实现呀,

------解决方案--------------------

PHP code
$result = round(35.5454,1);<br><font color="#e78608">------解决方案--------------------</font><br>$str = 35.5454;<br>$str = number_format($str, 1);  <br>echo $str;<br><font color="#e78608">------解决方案--------------------</font><br>
探讨

$str = 35.5454;
$str = number_format($str, 1);
echo $str;

------解决方案--------------------
PHP code
$str = 35.5454;$num =number_format($str,1)<br><font color="#e78608">------解决方案--------------------</font><br>$xxx=sprintf('%.1f',$xxx);<br><font color="#e78608">------解决方案--------------------</font><br>$result = round(35.5454,1);<br><font color="#e78608">------解决方案--------------------</font><br>结帖给分吧。<br>真的在线么????<br><font color="#e78608">------解决方案--------------------</font><br>sprintf('%0.1f',$str);<br><font color="#e78608">------解决方案--------------------</font><br>飘过!<br><font color="#e78608">------解决方案--------------------</font><br>round(35.5454,1);<br><font color="#e78608">------解决方案--------------------</font><br>round(3.14159,1);<br><br>number_format(3.14159265,1,'.','');//这个效果更佳,尾数是 0 ,会自动补上0的<br><font color="#e78608">------解决方案--------------------</font><br>
探讨
round(3.14159,1);

number_format(3.14159265,1,'.','');//这个效果更佳,尾数是 0 ,会自动补上0的
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