本文介绍了四舍五入整数的10最接近的倍数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图找出如何一轮涨价 - 两种方式。例如:
I am trying to figure out how to round prices - both ways. For example:
Round down 43 becomes 40 143 becomes 140 1433 becomes 1430 Round up 43 becomes 50 143 becomes 150 1433 becomes 1440我在那里我有发言权的一个价格区间的情况:
I have the situation where I have a price range of say:
£143 - £193而我想要显示为:
of which I want to show as:
£140 - £200因为它看起来简洁多了
as it looks a lot cleaner
我如何能做到这一点任何想法?
Any ideas on how I can achieve this?
推荐答案我只想创造了几个方法;
I would just create a couple methods;
int RoundUp(int toRound) { return (10 - toRound % 10) + toRound; } int RoundDown(int toRound) { return toRound - toRound % 10; }模给我们的余数,在围捕 10的情况下 - R的带你到最近的十分之一,为本轮下跌你刚才减河pretty直线前进。
Modulus gives us the remainder, in the case of rounding up 10 - r takes you to the nearest tenth, to round down you just subtract r. Pretty straight forward.
更多推荐
四舍五入整数的10最接近的倍数
发布评论