我正在尝试将以下内容作为一行程序重现。
if($l < 10) $next = 5; return;
if($l < 20) $next = 10; return;
if($l < 30) $next = 15; return;
if($l < 40) $next = 20; return;
if($l < 50) $next = 25; return;
if($l < 60) $next = 30; return;
if($l < 70) $next = 35; return;
if($l < 80) $next = 40; return;
if($l < 90) $next = 45; return;
if($l < 100) $next = 50; return;(句法上不正确,但你明白了)
所以如果数字小于10,$next就是5,如果数字小于20,那么就是10。
$next = ((round($l, -1)-5));是我所能达到的最接近的,但这给出了
5
15
25
35
45
55
65
75
85不是想要的5,10,15,20 ..等
写这个的正确方法是什么?
发布于 2012-01-28 16:37:13
将数字加上10,然后将结果除以10并将其向下舍入为最接近的(底数)整数,然后您将得到乘以5的数字,这将得到您的结果……所以..。假设你的号码是47。
47 + 10 = 57
57 / 10 = 5.7
楼层5.7 =5
5x5 = 25
return floor(($i + 10)/10) * 5发布于 2012-01-28 16:37:12
(($l + 10) / 10) * 5会做到这一点的
发布于 2012-01-28 16:35:36
除以十(并将其舍入为整数),然后将其与5... 100/10=10 => 10*5=50相乘
https://stackoverflow.com/questions/9043944
复制相似问题