Best (safest) way to convert from double to int

前端 未结 8 895
感情败类
感情败类 2021-01-07 21:00

I\'m curious as to the best way to convert a double to an int. Runtime safety is my primary concern here (it doesn\'t necessarily have to be the fastest method, but that wou

8条回答
  •  生来不讨喜
    2021-01-07 21:59

    I would use option two. Short, clean and it works.

    You could also look into the BigInteger class in .Net4, and you wouldn't have to check for overflow.

    double foo = 1;            
    BigInteger bigint = new BigInteger(foo);
    

提交回复
热议问题