Company Events Academic NI Developer Zone Support Solutions Products & Services Contact NI MyNI

Format Specifier Examples

LabVIEW 8.5 Help
August 2007

NI Part Number:
371361D-01

»View Product Info

Refer to the syntax elements table for more information.

Type Argument(s) Format String Resulting String Comments
Automatic Formatting (%g)12.00%#g12If you specify #, LabVIEW removes trailing zeros. If you specify g, LabVIEW chooses scientific notation or floating-point notation based on the number to format.
12000000%#g1.2E+6
Decimal (%d)12.67score= %.0f%% score= 13%When you specify %f, LabVIEW rounds the argument. Use %% to format a single %. Use .0 to remove decimal.
Floating-Point (%f) 12.67Temp: %5.1fTemp: 12.7 The 5 in the Format String section specifies a width of 5, and the 1 specifies the number of digits to the right of the decimal, or precision.
12.67 N%5.3f12.670 N Units are valid only if you use the Format Into String or Scan From String functions. These are examples of physical quantity input. The second example shows how you can convert from one unit to another. The question mark indicates when the unit in the format specifier is in conflict with the input unit.
12.67 N%5.3{mN}f1267.000 mN
12.67 N%5.3{kg}f12.670 ?kg
Scientific Notation (%e)12.67%.3e1.267E+1Add ^ to change to engineering notation where the exponent is always a multiple of three.
12.67%^.3e12.670E+0
SI Notation (%p)12000000%.2p12.00MA value of .2 specifies that you want a precision of 2 digits in the resulting string. A value of _2 specifies that you want two significant digits in the resulting string. %p adds the SI prefixes.
12000000%_2p12M
Hexadecimal (%x)12%02x 0C A – indicates that you want the resulting string left justified. A 0 indicates that you want the resulting string padded with zeros. The number specifies the width of the resulting string. In other words, a value of –n pads the resulting string with spaces to the n width. b is base 2, o is base 8, and x is base 16.
Octal (%o)12%06o000014
Binary (%b)12%b1100
Relative Time (%t)91.80%.2t01:31.80LabVIEW formats elapsed time in terms of complete weeks (%W), days (%D), hours (%H), minutes (%M), seconds (%S), and fractions of seconds (%u). Refer to the Format Codes for the Time Format String for more time format codes.
91.8%<Hours:%H Minutes:%M Seconds:%S>tHours:00 Minutes:01 Seconds:31
Absolute Time (%T) 00:00:00.000 AM
1/1/2001
(Universal Time)
%<%.3X %x>T12:00:00.000 AM 01/01/2001 %T specifies absolute time. Any information you include with the < and > brackets indicates how you want to format the absolute time. This format, including the punctuation, changes based on the regional settings of the computer. The time changes based on the configured time zone for the computer. Refer to the Format Codes for the Time Format String for more time format codes.
00:00:00.000 AM
1/1/2001
(Universal Time)
%<%Y.%m.%d>T2001.01.01
00:00:00.000 AM
1/1/2001
(Universal Time)
%^<%.3X %x>T06:00:00.000 AM 12/31/2000Add ^ to format the time in Universal Time.
String (%s)Smith JohnName: %s, %s. Name: Smith, John.Strings are valid only if you use the Format Into String function. In the second example, the format string specifies to use at most six characters from the string Hello, World then pad with spaces so the total string length is equal to 10.
Hello, WorldString: %10.6s String:   Hello,
Variable Order (%$)Smith John%2$s %1$s John SmithIn this example, Smith is the first variable and John is the second variable. If you use the $ syntax element in the format string for a particular variable, subsequent syntax elements that are not preceded by a $ syntax element apply to the next variable. If you use the $ syntax element for a variable, use the $ syntax element for any other variables in the string to improve readability.

Resources


 

Your Feedback! poor Poor  |  Excellent excellent   Yes No
 Document Quality? 
 Answered Your Question? 
Add Comments 1 2 3 4 5 submit