四舍五入整数的10最接近的倍数

编程入门 行业动态 更新时间:2024-10-13 08:21:57
本文介绍了四舍五入整数的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最接近的倍数

本文发布于:2023-11-07 23:29:19,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1567729.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:倍数   整数   最接近   四舍五入

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!