13.3.3 Number Types

The next three sections describe the input conversion of numbers. Each type of number (integer, money and real) uses a common routine to handle formats and unique routines to handle the standard input rules. The common routines handles formats in a manner similar to the output formatting. To save space, the common processing for numbers is described here and the peculiarities of each type is described later.

When a formatted input string is being converted to a number, the input string must "match" the format exactly. If the format specifies 10 digit specifiers (# or 0), there must be 10 blanks or digits. If the format specifies a currency symbol ($), the symbol defined for the country must appear in the input string. If fill is being done, the input string must have the correct fill characters. The table below shows some formats along with possible input strings and the conversion result.

Entry Format Input Result

1 ###,##0.00 123.45 123.45

2 ###,##0.00 123.45 Error

3 $#,##0.00 $ 234.56 234.56

4 $#,##0.00 1,234.56 Error

5 $*#,##0.00 $**234.56 234.56

6 $*#,##0.00 $**234 Error

7 $*#,##0 $ 234 Error

These examples only show the result of scanning the strings by format. When the standard input rules for REAL or MONEY types are applied, the second and fourth examples would be considered valid. Notice the sixth example. This example fails because it lacks a decimal point and the two digits following. The seventh example fails because it lacks the proper fill characters. These last two examples are why we recommend that system formats be as simple as possible. If the input strings are close to the format but not exact, the standard input rules may not be able to recover the number (as they can in the second and fourth examples).