Math.Floor vs cast to an integral type in C#

前端 未结 5 1107
清歌不尽
清歌不尽 2020-12-31 01:51

Are there any reasons one would prefer to use Math.Floor vs casting to an integral type?

double num;
double floor = Math.Floor(num);

OR

5条回答
  •  Happy的楠姐
    2020-12-31 02:29

    Even if you're only dealing with positive values, a double value doesn't always fit in a long.

    See ranges of long and double on MSDN.

提交回复
热议问题