将数字四舍五入到下一个百位 [英] Rounding a digit to the next hundred position
本文介绍了将数字四舍五入到下一个百位的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嗨朋友
我有一个像235的数字.我想将此数字四舍五入为300.例如85672-90000
我该如何实现
我使用了Math.cieling(number/100.000d)* 1000
但如果编号为312,则仍为312,而不是400
请帮助
问候
Chinnu
HI friends
I have a number like 235. i want to round this number to 300. Like 85672 - 90000
how can i achieve this
I used Math.cieling(number/100.000d)*1000
but if a no is 312 it wil remain as 312 not 400
Pls help
Regards
Chinnu
推荐答案
我刚刚尝试了它(因为它对我来说很好,除了乘法是一个数量级:
I just tried it (because it looks fine to me, excepting the multiply is out by an order of magnitude:
int i = 312;
Console.WriteLine(Math.Ceiling(i / 100.0d) * 100);
我得到的结果是"400".
您在做什么不同的事情?
The result I got was "400".
What are you doing differently?
这里有一个简单的解决方案:
Here''s a simple solution:
int x = 235;
int remainder = x % 100;
if (remainder > 0) {
x = x + (100 - remainder);
}
这篇关于将数字四舍五入到下一个百位的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文