Java rounding the results of a division when it shouldn't be

后端 未结 4 1058
心在旅途
心在旅途 2021-01-28 12:55

So I have some code for scaling graphics to the size of a users screen by dividing the size of an \'Ideal\' screen by the size of the users screen. Hers is a code snippet of wha

4条回答
  •  既然无缘
    2021-01-28 13:46

    If you're talking about this GameContainer class, getWidth() and getHeight() return an int.

    So you have to cast it as double

    scaleFactorWidth = (double)2880 / ui.getWidth();
    scaleFactorHeight = (double)1800 / ui.getHeight();
    

提交回复
热议问题