Dividing by two integers does not return expected result

前端 未结 6 599
甜味超标
甜味超标 2021-01-25 13:18

I\'m currently writing a program that requires a preview of a live display, but the preview, of course, is scaled down. However, when I scale the PictureBox down, t

6条回答
  •  伪装坚强ぢ
    2021-01-25 13:23

    You are doing integer division:

    double ratio = 4 / 3; // evaluates to 1
    

    This won't give you the value you are looking for because the decimal point is being truncated, thus evaluating to 1 instead of 1.333. At least one of the operands needs to be a double:

    double ratio = 4.0 / 3.0; // evaluates to 1.333
    

    Same goes for Height. Change the 4 to 4.0.

提交回复
热议问题