Formatting and I/O Library Chapter 2
LabWindows/CVI Standard Libraries 2-52 © National Instruments Corporation
Fmt (buf, "%s<%f[p0]", x); /* result: "12." */
x = 12.345;
Fmt (buf, "%s<%f[p6]", x); /* result: "12.345000" */
x = -12.345;
Fmt (buf, "%s<%f[w12]", x); /* result: "-12.345" */
x = -12.3456789;
Fmt (buf, "%s<%f[w6]", x); /* result: "-12.3*" */
x = 0.00000012;
Fmt (buf, "%s<%f[p8]", x); /* result: "0.00000012" */
x = 0.00000012;
Fmt (buf, "%s<%f", x); /* result: "1.2e-007" */
x = 4.5e050;
Fmt (buf, "%s<%f", x); /* result: "4.5e050" */
Remarks
The results shown are the contents of buf after each call to Fmt. The last two calls demonstrate
that very large and very small values are sometimes forced into scientific notation even when the
e modifier is absent.
Real to String in Scientific Notation
char buf[20];
double x;
x = 12.3456789;
Fmt (buf, "%s<%f[e]", x); /* result: "1.234568e+001" */
x = 12.3456789;
Fmt (buf, "%s<%f[ep2]", x); /* result: "1.23e+001" */
x = 12.3456789;
Fmt (buf, "%s<%f[e2p2]", x); /* result: "1.23e+01" */
x = 12.345;
Fmt (buf, "%s<%f[e]", x); /* result: "1.234500e+001" */
x = 12.345;
Fmt (buf, "%s<%f[ep2w12]", x); /* result: " 1.23e+001" */
x = 12.345;
Fmt (buf, "%s<%f[ep2w6]", x); /* result: "1.23e*" */
Remarks
The results shown are the contents of buf after each call to Fmt. The last call demonstrates
what occurs when the width specified by the w modifier is too small.