Home > Backend Development > PHP Tutorial > 怎么进行向上取整,以500递增

怎么进行向上取整,以500递增

WBOY
Release: 2016-06-13 12:16:48
Original
1804 people have browsed it

如何进行向上取整,以500递增
条件:
以500递进,
规则:如现在是4200,则自动使其变成4500;如现在是4700,则变成5000;4500或者5000这种不变,请支招
------解决思路----------------------

$d = array(4200, 4700, 5000, 4500);<br /><br />foreach($d as $v) {<br />  printf("%d : %d\n", $v, ceil($v/500)*500);<br />}
Copy after login
4200 : 4500<br />4700 : 5000<br />5000 : 5000<br />4500 : 4500<br /><br />
Copy after login

------解决思路----------------------
<br />$vl=4500;<br />$vl=((int)($vl/500))*500+($vl%500==0?0:500);<br />echo $vl;<br />
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