四舍五入至最接近的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;