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

后端 未结 6 594
一生所求
一生所求 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:41

    According to MSDN, Math.Floor(double) returns a double: http://msdn.microsoft.com/en-us/library/e0b5f0xb.aspx

    If you want it as an int:

    int result = (int)Math.Floor(yourVariable);
    

    I can see how the MSDN article can be misleading, they should have specified that while the result is an "integer" (in this case meaning whole number) it is still of TYPE Double

提交回复
热议问题