Dividing by two integers does not return expected result

前端 未结 6 602
甜味超标
甜味超标 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:28

    Make sure division result is double

    double ratio = (double) 4 / 3; // double division 
    

    and no need to set your input values to double.

    var num1 = // an integer number
    var num2 = // an integer number
    
    //result is integer, because of integer/integer uses 'integer division'
    double result = num1 / num2; 
    
    //result is double , because of you forced to 'double division'
    double result = (double) num1 / num2;
    

提交回复
热议问题