07-02-2024, 07:41 AM
(07-02-2024, 07:19 AM)SMcNeill Wrote: I'd never swear to this type of glitch being fully squashed. VAL returns a floating point value to us. Not all floating point values work out to be exactly what we'd think they might be. x = VAL("10") may somehow magically return a value of 9.9999999999999999 due to the way floating point numbers work. QB4PE tries to avoid this issue, as much as possible, but it's an underlying component of just the way floating point works.Alright. That's what I thought was happening. I am working on a project called Strek (which you can find in the Games forum).
Any time you work with floating point values, I'd never swear that you'd get exact integers. If you want integers, then assign it to an integer variable. Chances are, if the value ends up being 9.99999999999 or 1.0000000000001e12, or whatever, it'll end up rounding to the proper value for you naturally.
Code: (Select All)x$ = "9"
x& = Val(x$)
x = x&
Print x
End
I was trying to convert a string array to Integer and it returned values of less than 1 for conversion.
Thought it was an error in my code but apparently not.
Erik.