in reply to dependable way to test for a float

When doesn't it work? What do you want to differentiate a float from?

Caution: Contents may have been coded under pressure.

Replies are listed 'Best First'.
Re^2: dependable way to test for a float
by vindaloo (Acolyte) on May 05, 2005 at 00:16 UTC

    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.

      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?