How do I round a float upwards to the nearest int in C#?

后端 未结 6 1070
悲哀的现实
悲哀的现实 2020-12-08 09:43

In C#, how do I round a float upwards to the nearest int?

I see Math.Ceiling and Math.Round, but these returns a decimal. Do I use one of these then cast to an Int?<

6条回答
  •  北海茫月
    2020-12-08 10:12

    You can cast to an int provided you are sure it's in the range for an int (Int32.MinValue to Int32.MaxValue).

提交回复
热议问题