c# - Dividing two numbers always equals zero? -
in xna game, trying have playfield scale screen running on. this, use proportions find percent real window scaled relative playfield. this, divide real width virtual width:
float _percent = _realviewport.width / this._viewport.width; i 0, though, in _percent variable. set debug stop point @ line in code, , analyzed variables. this._viewport.width equals 640, , _realviewport.width equals 1280. so, using calculator, 640 / 1280 should equal 0.5, in code 0 out, instead of 0.5. why doing this?
because integer division truncates (xna's viewport type has integer width , height properties), , 640 / 1280 0.5, truncates zero.
cast 1 of values float if want floating point division:
float _percent = _realviewport.width / (float)this._viewport.width;
Comments
Post a Comment