Why does Math.Floor(Double) return a value of type Double?

后端 未结 6 591
一生所求
一生所求 2020-12-10 10:22

I need to get the left hand side integer value from a decimal or double. For Ex: I need to get the value 4 from 4.6. I tried using Math.Floor function but it\'s returning a

6条回答
  •  攒了一身酷
    2020-12-10 10:31

    If you just need the integer portion of a number, cast the number to an int. This will truncate the number at the decimal point.

    double myDouble = 4.6;
    int myInteger = (int)myDouble;

提交回复
热议问题