我如何四舍五入到最接近的0.5? [英] How do I round to the nearest 0.5?

查看:501
本文介绍了我如何四舍五入到最接近的0.5?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要显示评分和我需要的增量如下:

I have to display ratings and for that i need increments as follows:

如果数目是1.0,应该等于1

如果数字为1.1应该等于1

如果数字为1.2应该等于1

如果数字为1.3应等于1.5

如果数字为1.4应等于1.5

如果数字为1.5应等于1.5

如果数字为1.6应等于1.5

如果数字为1.7应等于1.5

如果数字为1.8应等于2.0

如果数字为1.9应等于2.0

如果数字为2.0应等于2.0

如果数字为2.1应等于2.0

等等...

If the number is 1.0 it should be equal to 1
If the number is 1.1 should be equal to 1
If the number is 1.2 should be equal to 1
If the number is 1.3 should be equal to 1.5
If the number is 1.4 should be equal to 1.5
If the number is 1.5 should be equal to 1.5
If the number is 1.6 should be equal to 1.5
If the number is 1.7 should be equal to 1.5
If the number is 1.8 should be equal to 2.0
If the number is 1.9 should be equal to 2.0
If the number is 2.0 should be equal to 2.0
If the number is 2.1 should be equal to 2.0
and so on...

有没有一种简单的方法来计算所需的值?

Is there a simple way to compute the required values?

推荐答案

乘以2你的等级,然后用圆 Math.Round(等级,MidpointRounding.AwayFromZero),然后除以2的值。

Multiply your rating by 2, then round using Math.Round(rating, MidpointRounding.AwayFromZero), then divide that value by 2.

这篇关于我如何四舍五入到最接近的0.5?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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