如何在PHP中舍入整数? [英] How to round up integer in PHP?
本文介绍了如何在PHP中舍入整数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想将任何一个整数向上舍入到下一个十位数。
I want to round up any an integer to the next tens place number.
一些例子来说明我的观点:
Some examples to illustrate my point:
- 我的数字是1,我希望这个数字为10美元
-- I have the number 1, I would like this rounded up to 10
- 我有数字35,我希望这个数字四舍五入到40
-- I have the number 35, I would like this rounded up to 40
- 我的数字是72,我希望这个数字可以达到80
-- I have the number 72, I would like this rounded up to 80
- 等等
// $category_count's value is 38
for($i = 1; $i <= $category_count; $i++)
{
if($i % 10 == 0)
{
echo "<a href=\"?page=$i\">$i;</a>";
}
}
以上代码输出3个链接,我需要第四个
The above code outputs 3 links, I need the fourth too.
推荐答案
的无效。如果你需要模数10你的计数器,请使用此代码:
Your for
is ineffective. If you need to modulus 10 your counter, use this code instead :
for($i = 1, $c = ceil($category_count/10); $i <= $c; $i++)
{
$j = $i * 10;
echo "<a href=\"?page=$j\">$j;</a>";
}
这篇关于如何在PHP中舍入整数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文