Cast to int vs floor

前端 未结 7 1619
夕颜
夕颜 2020-11-27 14:25

Is there any difference between these:

float foo1 = (int)(bar / 3.0);
float foo2 = floor(bar / 3.0);

As I understand both cases have the sa

7条回答
  •  粉色の甜心
    2020-11-27 14:38

    SO 101, do not change your question after people have replied to your question, instead write a new question.

    Why do you think they will have the same result?

    float foo = (int)(bar / 3.0) //will create an integer then assign it to a float
    
    float foo = fabs(bar / 3.0 ) //will do the absolute value of a float division
    
    bar = 1.0
    
    foo1 = 0;
    foo2 = 0.33333...
    

提交回复
热议问题