[RESOLVED] 20.0 - 12.0 = 7.999999... ???
Hi, I'm using an array of PointF variables.
When calculating with the coordinates I something like 20.0 - 12.0 = 7.9999
The PointF-var has a X and Y variable (both are singles), why on earth do I get such a result when using it like this:
NewsingleVar = MyPointF(1).x -MyPointF(2).x
Re: 20.0 - 12.0 = 7.999999... ???
I had this problem in a game I wrote. It's because they are floats and something about accuracy loss or something like that..
Just use the overloaded version of the ToString method to format it. Or some other format method.
Re: 20.0 - 12.0 = 7.999999... ???
This is one of the drawbacks of using floating-point numbers. If all values are whole numbers then you should use Point rather than PointF values. Otherwise you could try rounding results to a specific number of significant digits if all your original values are also to that many significant digits. If there's division involved anywhere it starts to get more complex though.
Re: 20.0 - 12.0 = 7.999999... ???
Thanks for the reply.
I need the values to be single, so there no change needed.
I found this one only will testing and got a bit worried.
Looks like I didn't do anything wrong, so I'm fine.
Thanks