in reply to dependable way to test for a float

From the perl cookbook section 2.1, with my own reformatting and comments:
sub isThisADecimalNumber { my ($string) = @_; return $string =~ /^\s* -? # negative sign - optional (?: \d+ # digits (?:\.\d*)? # and an optional decimal and +maybe more digits | # OR \.\d+ # a decimal and some digits ) \s*$/x; }

Replies are listed 'Best First'.
Re^2: dependable way to test for a float
by vindaloo (Acolyte) on May 05, 2005 at 00:05 UTC
    An optional decimal would not be a float, so I think this is not testing for a float.
      I see your point. My test is more to check if a string is numeric or not, not exactly is this number a float.