# Numeric Output

For BBj-Specific Information, see Numeric Output – BBj.

PRO/5 internally stores numeric values in a form appropriate for calculations. There are times when a numeric value must be converted into human-readable form. This will happen when LISTing a program line containing numeric constants, when printing a number with an output verb, such as PRINT, and when using the STR() function.

When LISTing a program line, PRO/5 will display numeric constants independent of any current precision settings. The full value of the constant will always be shown.

When outputting the number through an output verb or through the STR() function, you have the option of letting PRO/5 format the number, or you may specify a format using a format mask. Here are some examples of conversion without a mask:

PRINT X
LET A\$=STR(X)

If no mask is given, PRO/5 will round the number to the current precision and then create a string representing the number. A minus sign and a decimal point will be used only if necessary. If the magnitude and precision of the number are such that more than 16 digits will be necessary, or if the current precision setting is FLOATINGPOINT, PRO/5 will use "E" notation to show the number.

The following examples show conversion using a mask:

PRINT X:"\$##,###.00"
LET X\$=STR(A:"#,##0.000")

When using a format mask, PRO/5 formats the number using the mask string as a guide. The resulting string is always the same size as the mask. PRO/5 performs the following steps when using a format mask:

1. PRO/5 scans the mask to determine its magnitude and precision. If the mask is null an !ERROR=43 is issued.

2. The number is rounded to the precision of the mask. If the rounded number exceeds the magnitude of the mask, PRO/5 issues an !ERROR=43. This can be overridden in the PRINT command using the SETOPTS verb.

3. If the first character of the mask is "*", then "*" becomes the FILL CHARACTER. Otherwise a space is used for the fill character.

4. PRO/5 scans the mask left-to-right, replacing each special character in the mask with an output character. The following is a list of special mask characters:

 Mask Character Description 0 A zero is always replaced by a digit(0..9). # The pound sign is used to suppress leading zeroes. It is replaced by the fill character for leading zeroes to the left of the decimal point. For trailing zeros to the right of the decimal point it is replaced by a space or a zero (see SETOPTS Byte 4, Bit \$04\$ for more detail). Any other time it is replaced by a digit. SeeSETOPTSfor more information. , To the left of the decimal point, the comma is replaced by the fill character if no digits have yet been placed. Any other time, it results in a comma. - The minus sign creates a "-" in the result if the number is negative; otherwise, it is replaced by the fill character. + The plus sign becomes a "+" in the result if the number is positive, or a "-" if the number is negative. \$ The dollar sign always results in a dollar sign. ( A left parenthesis results in a "(" if the number is negative, or the fill character if positive. ) A right parenthesis results in a ")" if the number is negative, or the fill character if positive. CR The characters "CR" are inserted into the number if the number is negative. Two spaces are inserted if the number is positive. DR The characters "CR" are inserted into the number if the number is negative. The characters "DR" are inserted if the number is positive. * The asterisk "*" is inserted into the number. . The decimal point is replaced by a decimal point if any digits appear in the output mask. Otherwise, it is replaced by the fill character. After the decimal point, the fill character becomes a space. B The upper case "B" always becomes a space. Any other character is simply copied to the result.

Some of the above characters may possibly float within the mask. These are "-", "+", "\$", and "(". If any of these characters is present in the mask, the first one encountered will be moved to the last position where a "#" or "," was replaced by the fill character. If no such position exists, the float character is left where it is.

NOTE: A mask within a control does NOT round, but a mask within the STR() DOES round. For example, when placing a value such as 12.34567 into an inputN control that is masked with ###0.00, you'll get 12.34. However, if in console mode you print str(12.34567:"###0.00"), you'll get 12.35.