Standard Flags

After the % sign (and before the format code letter), zero or more of the following flags may appear:

  • # (pound sign) Specifies that the value should be printed using an "alternate format", depending on the format code. For format code(s):

    • %o A non-zero result will be prepended with 0 (zero) in the output.

    • %x, %X A non-zero result will be prepended with 0x or 0X.

    • %e, %E, %f, %g, %G The result will always contain a decimal point, even if no digits follow it (normally, a decimal point appears in the results of those conversions only if a digit follows). For %g and %G conversions, trailing zeros are not removed from the result as they would otherwise be.

    • %b A non-zero result will be prepended with 0b.

  • 0 (digit zero) Specifies zero padding. For all numeric formats, the output is padded on the left with zeros instead of spaces.

  • - (negative field width) Indicates that the result is to be left adjusted in the output field instead of right. A - overrides a 0 flag if both are present. (For the %L extended code, this flag indicates the argument is a latitude.)

  • (a space) Indicates that a space should be left before a positive number produced by a signed format (e.g. %d, %i, %e, %E, %f, %g, or %G).

  • + (plus sign)

    If given with a numeric code, indicates that a sign always be placed before a number produced by a signed format. A + overrides a space if both are used.

    For the %L extended code, a + flag indicates the argument is a location - latitude and longitude, or geocode.

    If given with a string code, + indicates that if the string value exceeds the given precision, truncate the string by a further 3 bytes, and append an ellipsis ("..."). This can be useful to give an indication of when a value is being truncated on display. String code support was added in version 6.00.1340835555 20120627.

Examples:

<fmt "%#x %#x" 42 0>         <fmt "%+d %+d" 42 -42>
0x2a 0                       +42 -42

Following any flags, an optional width number may be given. This indicates the minimum field width to print the value in (unless using the m flag; see Metamorph Hit Mark-up, here). If the printed value is narrower, the output will be padded with spaces on the left. Note the horizontal spacing in this example (output is the right column):

Test results:                        Test results:
<$x = 42 12345 87654321 912>             42
<LOOP $x>                             12345
  <fmt "%6d" $x>                     87654321
                                        912
</LOOP>

After the width, a decimal point (.) and precision number may be given. For the integer formats (%d, %i, %o, %u, %x and %X), the precision indicates the minimum number of digits to print; if there are fewer the output value is prepended with zeros. For the %e, %E and %f formats, the precision is the number of digits to appear after the decimal point; the default is 6. For the %g and %G formats, the precision is the maximum number of significant digits (default 6). For the %s (string) format, it is the maximum number of characters to print. Examples:

  <fmt "Error number %5.3d:" 5>
  Error number   005:

  <fmt "The %1.6s is %4.2f." "answering machine" 123.456789>
  The answer is 123.46.

The field width or precision, or both, may be given as a parameter instead of a digit string by using an * (asterisk) character instead. In this case, the width or precision will be taken from the next (integer) argument. Example (note spacing):

<$width = 10>                              The value is:
<$prec = 2>                                    123.46
The value is:
<fmt "%*.*f" $width $prec 123.4567>

An h or l (el) flag may appear immediately before the format code for numeric formats, indicating a short or long value (l has a different meaning for %H, %/ and %:, see here). These flags are for compatibility with the C function printf(), and are not generally needed in Vortex because integers are automatically promoted to the largest type available in version 3.01.984500000 20010312 and later). In these versions, the w flag may be given to indicate a "whopping" (largest available, generally 64-bit) value.


Copyright © Thunderstone Software     Last updated: Dec 10 2018
Copyright © 2019 Thunderstone Software LLC. All rights reserved.