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

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

WBOY
WBOYOriginal
2016-06-13 12:16:481816browse

如何进行向上取整,以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 />}
4200 : 4500<br />4700 : 5000<br />5000 : 5000<br />4500 : 4500<br /><br />

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

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