Dividing two numbers always equals zero?

爱⌒轻易说出口 提交于 2019-12-02 00:34:21

Because integer division truncates (XNA's Viewport type has integer width and height properties), and 640 / 1280 is 0.5, which truncates to zero.

Cast one of your values to a float if you want floating point division:

float _percent = _realViewport.Width / (float)this._viewport.Width;

try this float _percent = _realViewport.Width * 1.0/ (float)this._viewport.Width;,by adding multiplication by 1.0, the integer will automatically convert to float.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!