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

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.

Replies are listed 'Best First'.
Re^4: dependable way to test for a float
by vindaloo (Acolyte) on May 05, 2005 at 02:51 UTC
    I will look into it more, I am really curious as to why this is happening.
Re^4: dependable way to test for a float
by vindaloo (Acolyte) on May 06, 2005 at 17:54 UTC
    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.