BlockWidth = 87
BlockHeight = 96
============================================================
int Width = (BlockWidth + 75);
int Height = (BlockHeight * 3) / (BlockWidth * 5) * Width;
char s[128];
wsprintf(s, "%d", Height);
MessageBox(0, s, "a" ,0);
为何这里会显示0呢?

解决方案 »

  1.   

    (BlockHeight * 3) / (BlockWidth * 5)=0
    然后*width还是0除法时候至少一方非整型结果才不是整型
      

  2.   

    int Height = (BlockHeight * 3) /(float)(BlockWidth * 5) * Width
      

  3.   

    (BlockHeight * 3) / (BlockWidth * 5) * Width < 1你用int来保存,所以就等于0;
      

  4.   

    int Width = (BlockWidth + 75); 
    int Height = (BlockHeight * 3) / (BlockWidth * 5) * Width; 
    --->float Width = (BlockWidth + 75); 
    float Height = (BlockHeight * 3.0) / (BlockWidth * 5.0) * Width;