Home > php教程 > php手册 > PHP中数字转为百分位,千分位,万分位。。。

PHP中数字转为百分位,千分位,万分位。。。

WBOY
Release: 2016-06-06 19:47:47
Original
2388 people have browsed it

今天做项目中,需要将文章点击量显示在页面中,需求中给的是多少多少万,虽然不是什么难事,但做程序员这么久了,需要考虑的不再是简单的实现,而且有效率和快捷, 虽然PHP自带的函数有number_format()可以做到实现千分位,但我要的是万分位, 通过查找,发

今天做项目中,需要将文章点击量显示在页面中,需求中给的是多少多少万,虽然不是什么难事,但做程序员这么久了,需要考虑的不再是简单的实现,而且有效率和快捷,

虽然PHP自带的函数有number_format()可以做到实现千分位,但我要的是万分位,

通过查找,发现了可以用以下这个方法:

<span>$num</span> = 86231<span>;
</span><span>#</span><span> 将数字转为万分位</span>
<span>echo</span> <span>$num</span>>10000?<span>sprintf</span>("%.1f", <span>$num</span>/10000):<span>$num</span>;
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 Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template