This set of examples show various methods to test for character, integer, and decimal values.
The various test methods came from a discussion on the PEG and suggestions by members and myself.
Typical time results per 100,000 iterations of the functions.
+--------------------------------------------------+ ¦-123 ¦ ¦ ¦ ¦fn-ISCHAR-loop: 31510 ms no Loop method ¦ ¦fn-ISCHAR: 3681 ms no DEC(x) error method¦ ¦fn-ISCHAR-trim: 4185 ms no TRIM method ¦ ¦fn-ISDECIMAL-loop: 8081 ms yes Loop method ¦ ¦fn-ISDECIMAL: 3747 ms yes DEC(x) error Method¦ ¦fn-ISDECIMAL-trim: 4051 ms yes Trim Method ¦ ¦fn-ISINTEGER: 4748 ms yes INT(x) error Method¦ ¦fn-ISINTEGER-trim: 3759 ms yes Trim Method ¦ ¦fn-IsNumber: 9658 ms yes Parse Method ¦ +--------------------------------------------------+ IC=ISCHAR ID=ISDECIMAL IS=ISINTEGER IN=ISNUMBER +--------------------------------------------------------------------+ ¦TXT IC ICloop ICtrim ID IDLoop IDTrim II IITrim IN ¦ ¦--------------- --- ------ ------ --- ------ ------ --- ------ ---¦ ¦-1,234,567.89 : no no no yes yes yes no no yes¦ ¦-1234,567.89 : no no no yes yes yes no no no ¦ ¦-1,234567.89 : no no no yes yes yes no no no ¦ ¦-1,2,34,567.89 : no no no yes yes yes no no no ¦ ¦-1,234,56.7.89 : yes no no no yes yes no no no ¦ ¦+1,234,567.89 : no no no yes yes yes no no yes¦ ¦1,234,567.89 : no no no yes yes yes no no yes¦ ¦-1,234,567 : no no no yes yes yes yes no yes¦ ¦-1234567 : no no no yes yes yes yes yes yes¦ ¦-1234567. : no no no yes yes yes yes no yes¦ ¦x : yes yes yes no no no no no no ¦ ¦ ¦ +--------------------------------------------------------------------+
The trim method is always faster but can lead to special case false positives
such as an integer with a decimal and nothing after the decimal or commas in
the wrong place.
The DEC and INT error methods are almost as fast but are not flexible.
The char tests are a bit subjective since numbers could be considered characters.
To make this simple only the fn-ISCHAR-loop tests numbers too.
Fast and easy would be to use the DEC and INT functions since they
are more restrictive and almost as fast as the trim method.
Jeff Pilant's isnumber approach is the most comprehensive parsing for commas
or decimals depending on the users format in the correct locations.
I believe it to be the most accurate. It does have a 3x time penalty
compared to the dec error function method.
One thing to note that the error test methods using DEC return a true if the
input is an integer so to progress an integer is also a decimal but
not the other way around.
;)
-daniel
Attachment | Size |
---|---|
isnumber.p | 13.59 KB |