The monadic system function ⎕FI is used in conjunction with ⎕VI to
validate a text string and convert it to numeric form. In both cases, the argument is a character
vector (or scalar), containing one or more sub-strings of characters separated
by blanks. For each non-blank
sub-string, ⎕VI returns a 1 if the sub-string
represents a valid number, and 0 if it does not. ⎕FI returns the numeric representation of the sub-string, or 0 if it
is not a valid number. Numbers are validated and converted in the same way as normal APL input. Scientific notation is supported, and negative numbers are prefixed by the high minus (¯ ) character. For example:
⎕FI '100.32 $4 2,,3 0 12.2 ¯3 +2 -2'
100.32 0 0 0 12.2 ¯3 0 0
⎕VI '100.32 $4 2,,3 0 12.2 ¯3 +2 -2'
1 0 0 1 1 1 0 0
⎕VI
and ⎕FI are usually used to validate
and convert user input, or to convert text files to numeric form. To allow users to enter negative numbers
using the ordinary (non-APL) minus sign, you can use ⎕SS to translate minus to high-minus first. To allow comma-delimited input, use ⎕SS to translate comma to space:
STRING←'3,-2,45.5,-0.08'
⎕VI STRING
0
⎕SS (STRING; ('-';','); ('¯';' '))
3 ¯2 45.5 ¯0.08
⎕VI ⎕SS (STRING; ('-';','); ('¯';' '))
1 1 1 1
⎕FI ⎕SS (STRING; ('-';','); ('¯';' '))
3 ¯2 45.5 ¯0.08
|