### Format

Category

Annotation

Function

Formats a string.

Syntax

    string = Format(template, value, ...);

Inputs

Name | Type | Default | Description
--- | --- | --- | ---
`template` | string | none | format control string
`value` | value list or string | no default | value to format
`...` |  |  | more values to format

Outputs

Name | Type | Description
--- | --- | ---
`string` | string | formatted string object

Functional Details

This module uses a format-control string and input values to create a formatted output string. Each insertion is matched to a format-control specification, which always begins with a `%` symbol. Strings, scalars, integers, and vectors can be formed into output strings.

`template` | is the format-control string used in creating the formatted output. It resembles a C-language `printf` format string. Data Explorer copies all characters other than format specifications to the output (see next parameter).
`value` | is the value to be placed in the output string. The character following the `%` controls the type of conversion:
`c` | single characters
`d` | integers
`f` | floating point (fixed number of digits following the decimal point)
`g` | general (scientific notation if appropriate)
`s` | strings. Note: `f` and `g` will also format 2- and 3-vectors and lists.
To output a `%`, use `%%`. You can insert numbers between the `%` and the conversion character to control the width of the field and the number of significant digits formatted. A minus sign (-) left-justifies the output in the field; the default is right-justification. A format control string of
    "%-10.4f"
indicates left justification of a floating-point number, minimum of 10 columns total, with 4 places to the right of the decimal point.

A single call to the Format module can format a maximum of 21 values. In the user interface, the default number of enabled `value` tabs is two. (Tabs can be added to the module icon and removed with the appropriate `...Input Tab` options in the `Edit` pull-down menu of the VPE.)

Script Language Examples

1. In this example, value1 is set to 32.567799

       value1 = 32.567799;

2. This outputs the string "number = 32.567799."

       output = Format("number = %f", value1);
       Echo(output);

3. This example outputs the string "number = 32.57."

       output = Format("number = %3.2f", value1);
       Echo(output);

4. This example outputs the string "number = 32.57."

       output = Format("number = %11.2f", value1);
       Echo(output);

5. In this example, value2 is set to 134569888 and value3 is set to "New York."

       value2 = 134569888;
       value3 = "New York";

6. This example outputs the string
   "number = 134569888.000000, state = New York."

       output = Format("number = %f, state = %s", value2, value3);
       Echo(output);

7. This example outputs the string "number = 134569888, state = New York."

       output = Format("number = %10.0f, state = %s", value2, value3);
       Echo(output);

8. This example outputs the string "number = 1.3457e+08, state = New York."

       output = Format("number = %g, state = %s", value2, value3);
       Echo(output);

9. This example outputs the string
   "number = 1.3457e+08, state = New York."

       output = Format("number = %g, state = %15s", value2, value3);
       Echo(output);

Example Visual Programs

    ContoursAndCaption.net
    GeneralImport1.net

    FormatListMacro.net

    InvalidData.net
    PlotTwoLines.net

    SalesOnStates.net

    Sealevel.net

See Also

Caption, Echo, Text

[ OpenDX Home at IBM | OpenDX.org ]