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

如何进行向上取整,以500递增

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-06-23 13:38:081118browse

条件:
以500递进,
规则:如现在是4200,则自动使其变成4500;如现在是4700,则变成5000;4500或者5000这种不变,请支招


回复讨论(解决方案)

$d = array(4200, 4700, 5000, 4500);foreach($d as $v) {  printf("%d : %d\n", $v, ceil($v/500)*500);}
4200 : 45004700 : 50005000 : 50004500 : 4500

$vl=4500;$vl=((int)($vl/500))*500+($vl%500==0?0:500);echo $vl;

echo (floor($a / 500) * 500) + ( ($a % 500) ? 500 : 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