舍入到下一个0.05用C [英] Round to Next .05 in C

查看:105
本文介绍了舍入到下一个0.05用C的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

考虑像一个浮点值的 1.82 由用户设置。如何找到下一个最高0.05的价值?对于给定的例子中,下一个最高值是1.85

Consider a float value like 1.82 set by the user. How do I find the next highest .05 value? For the given example the next highest value is 1.85.

有一个简单的办法还是没有考虑复杂的算法?我试图用地板上限功能拿出从浮子的距离到下一个最高和最低的整数。但我不知道如何着手,一旦我有这些信息。

Is there a simple way or does it take a complex algorithm? I tried to use floor and ceiling functions to come up with the distance from the float to the next highest and lowest Integers. But I'm not sure how to proceed once I have that info.

感谢。

推荐答案

乘以20,20使用吊顶,鸿沟。

Multiply by 20, use ceiling, divide by 20.

这篇关于舍入到下一个0.05用C的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆