Format()

Format() converts a numeric input into a formatted decimal string. The function uss str(). The formatting expression defines the output format.

PräprozessorThe function is also available in the Preprocessor, uses constansts
and does not create any machine code.

Syntax

string = format( formatSpec, Expression )

  • formatSpec: String(Constant), with the formatting instruction.
  • Expression: Expression with numeric result.

„Decimal String“ denotes the converted numerical value.

Format description
Zeichen Description
0 Placeholder for a number in the decimal string
. Placeholder for a dot. When Integer the placeholder will split the numeric display at this position. When Floating the decimal point will be at this position. If the dot is omitted, the floating value will show the whole part of the number only.
+ Placeholder for the sign. When negative, a „-“ is inserted, when positive, a „+“ is inserted.
- Placeholder for a negative sign. When negative a blank is inserted.

Other characters in formatSpec will not be interpreted and passed to the result string. Formatting is right aligned, starting from low to high order decimal.

Example

const F_CPU=20000000
avr.device = atmega328p
avr.clock  = F_CPU
avr.stack = 64
uart.baud = 19200
uart.recv.enable
uart.send.enable
dim var as integer
print 12;"format example"
print
print "constant:"
print "format('00000.00',12345)  : ";34;format("00000.00",12345);34
print "format('-00000.00',12345) : ";34;format("-00000.00",12345);34
print "format('-00000.00',-12345): ";34;format("-00000.00",-12345);34
print "format('+00000.00',12345) : ";34;format("+00000.00",12345);34
print "format('+00000.00',-12345): ";34;format("+00000.00",-12345);34
print
print "variable:"
var=12345
print "format('00000.00',var)    : ";34;format("00000.00",var);34
print "format('-00000.00',var)   : ";34;format("-00000.00",var);34
print "format('-00000.00',-var)  : ";34;format("-00000.00",-var);34
print "format('+00000.00',var)   : ";34;format("+00000.00",var);34
print "format('+00000.00',-var)  : ";34;format("+00000.00",-var);34
print
print "ready"
do
loop

Output