in reply to Re: dependable way to test for a float
in thread dependable way to test for a float

I have not totally isolated when it does not work yet. I am testing for a floating point number to separate from both booleans and strings all of which are values in a hash.

I just had deja vu writing this....yet no recollection of doing this in a past life.

  • Comment on Re^2: dependable way to test for a float

Replies are listed 'Best First'.
Re^3: dependable way to test for a float
by Roy Johnson (Monsignor) on May 05, 2005 at 02:22 UTC
    For your purposes, are the integers not floats? I can't think of any case where the int($n) != $n test wouldn't work. Or would it be a float if it were '0.0' (for example)?

    Though you haven't isolated when it doesn't work, can you give any example for which it doesn't work?


    Caution: Contents may have been coded under pressure.
      I will look into it more, I am really curious as to why this is happening.
      The error was in the test and a variable being empty in the comparison. My code is working fine now. I did come across this though and wondered why:
      my $var = 23123412341234.01222222; print "var=$var\n"; if(int($var) != $var){ print "is a float\n"; } else{ print "not a float\n"; }
      Prints this:
      var=23123412341234 is a float
      The test is always working for me, so that is a good confirmation. However, I was wondering why it prints the integer before the int() function touches the variable?
        It's because the number is so long it can't be represented numerically. If you use bignum;, it will behave more like you probably expect.

        Caution: Contents may have been coded under pressure.