FORMAT$( nbr [, fmt$] )
MMbasic 4.5, not 5.0
Will return a string representing ‘nbr’ formatted according to the specifications in the string ‘fmt$’.
The format specification starts with a % character and ends with a letter. Anything outside of this construct is copied to the output as is.
The structure of a format specification is:
% [flags] [width] [.precision] type
Where ‘flags’ can be:
– Left justify the value within a given field width
0 Use 0 for the pad character instead of space
+ Forces the + sign to be shown for positive numbers
space Causes a positive value to display a space for the sign. Negative values still show the – sign
‘width’ is the minimum number of characters to output, less than this the number will be padded, more than this the width will be expanded.
‘precision’ specifies the number of fraction digits to generate with an e, or f type or the maximum number of significant digits to generate with a g type. If specified the precision must be preceded by a dot (.).
‘type’ can be one of:
g Automatically format the number for the best presentation.
f Format the number with the decimal point and following digits
e Format the number in exponential format
If uppercase G or F is used the exponential output will use an uppercase E. If the format specification is not specified “%g” is assumed.
PRINT FORMAT$(45)
45
PRINT FORMAT$(45, "%g")
45
PRINT FORMAT$(24.1, "%g")
24.1
PRINT FORMAT$(24.1, "%f")
24.100000
PRINT FORMAT$(24.1, "%e")
2.410000e+01
PRINT FORMAT$(24.1, "%09.3f")
00024.100
PRINT FORMAT$(24.1, "%+.3f")
+24.100
PRINT FORMAT$(24.1, "**%-9.3f**")
**24.100 **
See also:
INSTR
LCASE
LEFT$
LEN
MID$
RIGHT$
SPACE$
SPC
STRING$
UCASE$
Applies to:
CGCOLORMAX
CGMMSTICK
CGMICROBOARD
CGMICROMITE
Leave a Reply