View Full Version : Testing variables
04-07-2012, 07:12 PM
I use numbers.stringtonumber and the string is "1.2" and store the returned number as NUMBER.
Can I then test it so that IF NUMBER > 2.2 something happens or will the test only work on the integer parts - or will something else happen?
04-07-2012, 07:30 PM
I assume NUMBER is a float?
If so, you'd use FCmp in F32.spin.
You can't use any of the normal operators on floats.
04-07-2012, 07:34 PM
Have you learned about pseudo-real numbers?
Instead of using 2.1, you'd use 21 but know it has been multiplied by ten and and treat it accordingly.
One rarely needs to use floating point numbers if you're just adding, subtracting, multiplying and dividing.
04-07-2012, 07:39 PM
I also use the method Duane mentions, with multiplying by 10 to get an integer. Like you, I struggled with numbers and floats, but started using this and I do not hardly ever use floats anymore.
04-08-2012, 09:12 AM
Interesting. I have several things that are working despite my ineptitude. I can only assume that the Numbers object's Num.FromStr routine is doing the truncating and "integerising" of the floating point decimal strings. My routines give the correct results to it must be so.
EDIT: a quick test shows this to be the case.