Click or drag to resize

Formatting Floating-Point Input Parameters

Floating-point numbers used as input parameters to method and property commands can be formatted in a variety of ways. Scalar floating-point parameters are formatted as ASCII text and sent to the instrument. Floating-point arrays can be sent to the instrument in the following formats:

  • An ASCII list of values separated by commas or another specified delimiter.

  • An IEEE 488.2 binary block.

This topic presents the format specifications for sending data to the device as ASCII text. For detailed information on sending array data as IEEE binary blocks, see the topic Reading and Writing IEEE 488.2 Binary Block Data.

Floating-point numbers used as input parameters have format specifications of the following general form:

%[flags] [488.2 type] [width] [.precision] [delimiter] [f | e | E | g | G]

Modifier

Interpretation

flags

+, -, 0

Controls justification and padding of the output, as follows:

  • - - left aligns the result with the given field width.

  • + - prefixes the output value with a sign (+ or –) if the output value is of a signed type. By default, a sign only appears for negative values.

  • 0 pads with zeros until the specified width is reached. If 0 and - appear together, the 0 is ignored.

488.2 type

The number is formatted in one of six standard IEEE 488.2 numeric formats. The supported formats are:

  • @1 - IEEE 488.2 NR1 format (integer without any decimal point). Example: 123

  • @2 - IEEE 488.2 NR2 format (number with at least one digit after the decimal point). Example: 123.45

  • @3 - IEEE 488.2 NR3 format (floating-point number in exponential form). Example: 1.2345E-67

  • @H - IEEE 488.2 hex format. Example: #HAF35B

  • @Q - IEEE 488.2 octal format. Example: #Q71234

  • @B - IEEE 488.2 binary format. Example: #B011101001

width

Specifies the minimum field width of the converted number. If an argument is shorter than the field width, it will be padded on the left (or on the right if - is present in the flags field.

If @H, @Q, and @B is specified as the 488.2 type, then the width includes the #H, #Q, and #B strings, respectively.

precision

Maximum number of digits after the decimal point for %f, %e, %E.

Maximum number of significant digits for %g, %G.

The default precision is 6.

delimiter

The parameter must be an array of floating-point numbers. The elements of the array are sent to the device with the specified delimiter between each element.

The following delimiters are supported. Note that the enclosing parentheses are not required for comma-separated lists:

  • , or (,) - comma-separated list

  • (;) - semicolon-separated list

  • (:) - colon-separated list

  • (s) - space-separated list

  • (t) - tab-separated list

  • (r) - carriage return-separated list

  • (n) - linefeed-separated list

type

  • f - signed value having the form dddd.dddd

    where dddd is one or more digits.

    The number of digits before the decimal point depends on the magnitude of the number, and the number of digits after the decimal point depends on the requested precision.

    Example: 3.1415

  • e - signed value having the form d.dddde [+ | -]ddd

    where d is a single digit, dddd is one or more digits, ddd is exactly three digits.

    Example: 3.14e-123

  • E - identical to e format except that E rather than e introduces the exponent.

    Example: 3.14E-123

  • g - signed value in f or e format, whichever is more compact for the given value and precision.

    The e format is used only when the exponent of the value is less than –4 or greater than or equal to the precision.

    Trailing zeros are truncated, and the decimal point appears only if one or more digits follow it.

  • G - Identical to the g format, except that E, rather than e, introduces the exponent (where appropriate)..

Examples: Input Floating-Point Parameter

Parameter Tag

Data Sent to Device

{Frequency:%f}

300.000000

Default precision is 6.

{Frequency:%4.2f}

300.00

Field width is 4, but required length is greater.

{Frequency:%8.2f}

\s\s300.00

Width requires padding.

{Frequency:%8.2e}

3.00e+02

Exponential notation.

{FrequencyArray:%4.2,3f}

1.10,1.20,1.30

Comma-separated list.

{FrequencyArray:%4.2,3E}

1.10E+00;1.20E+00;1.30E+00;1.40E+00

Semi-colon-separated list of exponential values.

See Also

Download a complete CHM version of this documentation here.