How to remove decimal part from a number in C#

后端 未结 7 768
予麋鹿
予麋鹿 2020-12-08 04:12

I have number of type double. double a = 12.00 I have to make it as 12 by removing .00

Please help me

7条回答
  •  独厮守ぢ
    2020-12-08 04:21

    If you just need the integer part of the double then use explicit cast to int.

    int number = (int) a;
    

    You may use Convert.ToInt32 Method (Double), but this will round the number to the nearest integer.

    value, rounded to the nearest 32-bit signed integer. If value is halfway between two whole numbers, the even number is returned; that is, 4.5 is converted to 4, and 5.5 is converted to 6.

提交回复
热议问题