四舍五入至最接近的0.5 [英] Rounding of nearest 0.5

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

问题描述

我想以此方式四舍五入

13.1, round to 13.5
13.2, round to 13.5
13.3, round to 13.5
13.4, round to 13.5
13.5 = 13.5
13.6, round to 14.0
13.7, round to 14.0
13.8, round to 14.0
13.9, round to 14.0

很抱歉,我需要以上述方式进行修改...这样做但不合适

sorry for modification i need in the above way... did this way but not appropriate

doubleValue = Math.Round((doubleValue * 2), MidpointRounding.ToEven) / 2;

推荐答案

如果 13.1必需,请四舍五入为13.5 ,而 13.9则需要四舍五入为14.0 ,然后:

double a = 13.1;
double rounded = Math.Ceil(a * 2) / 2;

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

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