background image
Original Author Paul Laughton, 2011
Page 75
De Re BASIC!
% Character
(after decimal)
The "%" character is not allowed after the decimal point. This is a syntax error.
Non-pattern
Characters
If any pattern character (other than the first) is not # or %, then that character is
copied directly into the output. If the character would appear before the first digit
of the number, it is replaced by a space. This feature is usually used for commas.
Overflow
If the number of digits exceeds the number of # and % characters, then the output
has the ** characters inserted in place of the Floating Field.
Output Size
The number of characters output is always the number of characters in the pattern
plus one for the sign
plus one more for the space if the pattern has no Floating Character.
Notes
The sign and the floating character together form a Floating Field two characters wide that always
appears just before the first digit of the formatted output. If there are any leading spaces in the
formatted output, they are placed before the floating field.
The "#" character generates leading spaces, not leading zeros. "##.###" formats 0.123 as ".123". If you
want a leading zero, use a "%". For example "%.###", "#%.###", or "##%" all assure a leading zero.
Be careful mixing # and % characters. Doing so except as just shown can produce unexpected results.
The number of characters output is always the number of characters in the pattern plus the two floating
characters.
Examples
Function Call
Output
Width
Format$( "##,###,###", 1234567)
1,234,567
12 characters
Format$( "%%,%%%,%%%.#", 1234567.89) 01,234,567.8 14 characters
Format$( "$###,###", 123456)
$123,456
9 characters
Format$( "$###,###", -1234)
-$1,234
9 characters
Format$( "$###,###", 12)
$12
9 characters
Format$( "$%%%,%%%", -12)
-$000,012
9 characters
Format$( "##.#", 0)
.0
6 characters
Format$( "#%.#", 0)
0.0
6 characters
Format$( "$###.##", -1234.5)
**234.50
8 characters
User-Defined Functions
User-Defined Functions are BASIC! functions like ABS(n), MOD(a,b) and LEFT$(a$,n) except that the
operation of the function is defined by the user. User functions should generally be defined at the start
of the program and in particular, they should appear before the places where they are called.
User-Defined Functions may call other User-Defined Functions. A function can even recursively call itself.
You may define a function with the same name as a built-in function. The User-Defined Function always
overrides the built-in function, and the built-in function is not accessible.