Syntax

result = STR$(number, format)

Arguments

result: text

number: numeric

format: see table below

Meaning

Converts a number to a character string according to the indicated format.

A series of special characters (conversion characters) indicates how long the character string is to be, as well as the position of the digits, commas, decimal points and signs. The length of the result is always equal to the length of the code. The following conversion characters are allowed:

Z

Number position

For all occurrences of Z a digit will be printed. Leading zeros show as blanks.

#

Number position

For all occurrences of # a digit will be printed. Leading zeros show as zeros.

+

Character position

A single + will cause the sign (+ or -) to be printed in the corresponding position in the output. Multiple + characters will be replaced by printing digits in the number and the sign will be printed in the position immediately to the left of the leftmost printed character. If the format string ends with a +, the sign (- or +) will be in the rightmost position.

-

Character position

As +, except that a blank is printed instead of a + sign if the number is positive.

CR

Character position

The characters CR may only be used in the last two positions (rightmost part) of the string. If the number is negative the letters CR (“credit”) will be printed. If positive, two spaces will be printed.

$

Dollar position

A $ may only be preceded by a single sign character. A single $ will cause a $ to be printed in the corresponding position in the output. Multiple dollar signs will be replaced by printing characters in the number, and a single $ will be printed in the position immediately to the left of the leftmost printed character.

,

Comma position

The comma can be used as a punctuation mark in the part of a number that precedes the decimal point. The comma is used if the preceding character produces a number, otherwise, a space (or pad character) will be used.

.

Decimal point position

ADAPL uses the full stop as a decimal point. Following the full stop, only fixed numbers (#) and the characters +, - or CR may be used.

*

Pad character

Replaces blanks with asterisks. May be preceded by +, - or $.

If the number does not fit in the format, the result will be a series of asterisks ('******') of the same length as the format.

Example

In the interest of clarity, spaces are represented by 'x's.

Number

Format

Result

456

'####'

'0456'

45678

'####'

'****' too large!

0

'####'

'0000'

456

'ZZZZ'

'x456'

4567

'ZZZZ'

'4567'

0

'ZZZZ'

'xxxx'

0

'ZZZ#'

'xxx0'

5.045

'#.##'

'5.05' rounded

0

'#.##'

'0.00'

4567.89

'ZZZ,ZZZ,ZZ#.##'

'xxxxxx4,567.89'

456789.01

'ZZZ,ZZZ,ZZ#.##'

'xxxx456,789.01'

0

'ZZZ,ZZZ,ZZ#.##'

'xxxxxxxxxx0.00'

4

'+###'

'+004'

-4

'+###'

'-004'

4

'-ZZ#'

'xxx4'

-4

'-ZZ#'

'-xx4'

456

'ZZZZZ+'

'xx456+'

-456

'ZZZZZ+'

'xx456-'

456

'ZZZZZ-'

'xx456x'

-456

'ZZZZZ-'

'xx456-'

45678

'ZZZ,ZZ#CR'

'x45,678xx'

-45678

'ZZZ,ZZ#CR'

'x45,678CR'

456

'+++,++#.##'

'xxx+456.00'

-456

'+++,++#.##'

'xxx-456.00'

52

'$ZZZZZZ#'

'$xxxxx52'

52

'$$$$$$$#'

'xxxxx$52'

456321

'$***,***,**#.##'

'$****456,321.00'

See also

VAL