Keysight VISA.NET Help
Reading Floating Point Numbers

Reading Floating-point Numbers

A floating-point argument has a format specifier in one of the following forms:

f[*|@2|@3][width][,[arraySize]]f

e[*|@2|@3][width][,[arraySize]]e

E[*|@2|@3][width][,[arraySize]]E

g[*|@2|@3][width][,[arraySize]]g

G[*|@2|@3][width][,[arraySize]]G

Note that they are identical except for the format type.

Modifier

Interpretation

Default Functionality

The argument is interpreted as a floating point number.

flags

*

@2, @3

Controls parsing, as follows:

  • '*' indicates that the data is to be parsed and skipped - there is no corresponding output argument in the Scanf call.
  • '@2' formats the value in IEEE 488.2 NR2 format.
  • '@3' formats the value in IEEE 488.2 NR3 format.

width

For types e, E, and f, the actual number of digits after the decimal point.

For types g and G, the actual number of significant digits.

A hash character (#) may be present in lieu of an integer width modifier, in which case an extra Int32 argument supplies the value.

,[arraySize]

Format an array of integers converted to strings.  If arraySize is specified, it is the maximum number of elements to include in the formatted array.

A hash character (#) may be present in lieu of an integer arraySize modifier, in which case an extra Int32 argument supplies the value.

Floating Point Parsing Code Snippets

Remember that Scanf is reading bytes from the formatted read buffer, parsing them according to the format specifiers, and placing the results in an output variable. The comment preceding each line shows the data being parsed by the snippet, and the resulting value that is returned in the corresponding output argument, like this: //  "<data to parse>",  "<value>".  The <value> may optionally be followed by a comment in parentheses.

For Scanf arrays, output array sizes are calculated from the size of the data. For ScanfArray, which is unsafe, the calling program must allocate an array that is guaranteed to be large enough to hold the parsed array.

Assume that the io variable is a valid reference to IMessageBasedFormattedIO.  Assume that result1 is an out argument declared as a .NET Single or Double.  Either type is capable of holding any of the numbers used in these snippets.

Flags
Copy Code

// "25.135, 3.5135e+01, -4.5135E+01 \n ", 25.135, 35.135, -45.135

io.Scanf("%f, %e, E*T", out result1);

// "25.135, 3.5135e+01, -4.5135E+01 \n ", 35.135

io.Scanf("%*f, %e, *E*T", out result1);

Width Modifiers
Copy Code

// "25.135\n", 25.1

io.Scanf("%4f%*T", out result1);

 

// "12345\n", 1234.0

io.Scanf("#f*T", new Int64[] { 4 }, out result1);

 

// "2.5135E+011", 25.135  (the trailing '1' is not parsed.)

io.Scanf("10E*T", out result1);

 

// "2.5135E+011", 251350000000.00

io.Scanf("#E*T", new Int64[] { 20 }, out result1);

IEEE 488.2 Format Modifiers
Copy Code

// "25.135\n", 25.135

io.Scanf("@2f*T", out result1);

 

// "2.5135E+001\n", 25.135

io.Scanf("@3e*T", out result1);

ScanfArray
Copy Code

// "1.23, 2.34, 3.45, 4.56\n", { 1.23, 2.34, 3.45, 4.56 } - Memory must be allocated

//   by the calling program.

Double[10] out1;

io.ScanfArray("%,f%*T", out1);

 

 


© Keysight Technologies 2015-2025