Skip to content

I/O Format Specifiers for Reading Floating-Point Numbers

A floating point argument has a format specifier of the following form:

%[*] [488.2 type] [width] [delimiter [array size] ] [$S] [l | L] [f | e | E | g | G]

ModifierInterpretation
Default FunctionalityCharacters are read from the device until an entire number is read. The number read may be in either IEEE 488.2 formats , also known as NRf; flexible numeric representation (NR1, NR2, NR3...); or (#H, #Q, and #B).
* (asterisk)An asterisk acts as the assignment suppression character. The input is scanned but not assigned to any parameters and is discarded.
488.2 typeThe 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
widthThe input number will be stored in a field at least this wide. A # may be present in lieu of an integer precision modifier, in which case an extra int argument supplies the value.
delimiter [array size]The argument is an array of float, double, or long double element as dictated by the length modifier field. If the $S modifier is present, the argument is assumed to be a pointer to a SAFEARRAY of floating-point elements. array size specifies the maximum number of array elements to store in the user array argument. A # may be present in lieu of an integer array size modifier, in which case an extra int argument supplies the value.
$SThe argument is a pointer to a SAFEARRAY of floating-point numbers.
length modifierl - argument is a pointer to a double.
L - argument is a pointer to a long double.
HRESULT hr = S_OK;
double dArg1;
double dArg2;
double dArg3;
// Instrument sends:
// "3.2, 1.53E-12, 0.021"
hr = io.Scanf(_T("%le,%le,%le"), &dArg1, &dArg2, &dArg3); // dArg1 == 3.2
// dArg2 == 1.53E-12
// dArg3 == 0.021
// Instrument sends:
// "3.2, 1.53E-12, 0.021"
hr = io.Scanf(_T("%le,%*le,%le"), &dArg1, &dArg2); // dArg1 == 3.2
// dArg2 == 0.21

Example — Floating-point length modifiers

Section titled “Example — Floating-point length modifiers”
HRESULT hr = S_OK;
double dArg1;
float fArg2;
// Instrument sends:
// "3.14, 3E-4"
hr = io.Scanf(_T("%lf,%f"), &dArg1, &fArg2); // dArg1 == 3.14
// fArg2 == 3E-4
HRESULT hr = S_OK;
double dArg;
// Field width controls how much is read for each argument
// Instrument sends:
// "12.3456"
hr = io.Scanf(_T("%5le"), &dArg); // dArg == 12.34
// Field width supplied using variables
// Instrument sends:
// "12.3456"
int nWidth = 5;
hr = io.Scanf(_T("%#le"), &nWidth, &dArg); // dArg == 12.34
HRESULT hr = S_OK;
double rgData[5];
// Comma-separated list of 3 elements
// Instrument sends:
// "1.23,4.0E-56,0.789"
hr = io.Scanf(_T("%,3le"), rgData); // rgData[0] == 1.23
// rgData[1] == 4E-56
// rgData[2] == 0.789
// Mixed delimiters, count supplied as a variable
// Instrument sends:
// "1.23;4.0E-56:0.789,-2"
int nCount = 5;
hr = io.Scanf(_T("%(;,:)#d"), &nCount, rgData); // rgData[0] == 1.23
// rgData[1] == 4E-56
// rgData[2] == 0.789
// rgData[3] == -2
// nCount is updated with actual count
ATLASSERT(nCount == 4);
// Comma-separated list. Argument is a SAFEARRAY.
// An array element count is not required since Scanf allocates the memory
// Instrument sends:
// "1.23,4.0E-56,0.789"
SAFEARRAY* psa = NULL;
hr = io.Scanf(_T("%,$Sle"), &psa); // psa[0] == 1.23
// psa[1] == 4E-56
// psa[2] == 0.789
// ... use SAFEARRAY result
// IMPORTANT: SAFEARRAY must be destroyed
hr = ::SafeArrayDestroy(psa);