Rounding of nearest 0.5

后端 未结 7 1087
灰色年华
灰色年华 2021-01-14 16:03

I want to be rounded off this way

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, roun         


        
7条回答
  •  栀梦
    栀梦 (楼主)
    2021-01-14 16:21

    var a = d == (((int)d)+0.5) ? d : Math.Round(d);
    

    d is a double.

提交回复
热议问题