Shop OBEX P1 Docs P2 Docs Learn Events
Testing variables — Parallax Forums

Testing variables

g3cwig3cwi Posts: 262
edited 2012-04-08 02:12 in Propeller 1
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?

Just wondering.

Regards

Richard

Comments

  • Duane DegnDuane Degn Posts: 10,588
    edited 2012-04-07 12:30
    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.
  • Duane DegnDuane Degn Posts: 10,588
    edited 2012-04-07 12:34
    BTW,

    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.
  • turbosupraturbosupra Posts: 1,088
    edited 2012-04-07 12:39
    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.
  • g3cwig3cwi Posts: 262
    edited 2012-04-08 02:12
    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.


    Cheers

    Richard


    EDIT: a quick test shows this to be the case.
Sign In or Register to comment.